我在一个项目上工作,我想在一个类中声明私有变量,因为我在许多地方都读到它比声明它们为公开要好,但是如何在main中访问它们呢?我应该使用哪种功能使它们可访问?我想通过功能解决系统问题,而不是像我做的那样。到目前为止,这就是我的代码,
#include <iostream>
#include <limits>
using namespace std;
class Equation
{
private:
int a1,a2,b1,b2,c1,c2;
public:
};
int main()
{
int a,b,c,d,e,f;
cout<<"\n"<<endl;
cout<<" **** Hello **** \n\n"<<endl;
cout<<"This is a program to solve a system of equation"<<endl``;
cout<<"Equations will look like a1*x+b1*y=c1"<<endl;
cout<<"and a2*x+b2*y=c2\n"<<endl;
cout<<"Enter the values for the first equation \n"<<endl;
while ((cout<<"Enter the value of a1 :\n")
&& !(cin >> a)) {
cout << "Invalid input, please enter a number \n"<<endl;
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
while ((cout<<"Enter the …Run Code Online (Sandbox Code Playgroud)