#include <iostream>
#include <string>
#include <math.h>
#include <fstream>
using namespace std;
class Storage
{
public:
Storage();
string information[10][7];
void SetInformation(string,int);
void GetInformation(int);
};
Storage::Storage(){cout<<"\nStorage Activated\n";}
void Storage::SetInformation(string,int i)
{//input
i--;
for (int j=0;j<7;j++)
{
switch(j+1)
{case 1: cout << "\nFirst Name: "; break;
case 2: cout << "\nLast Name: "; break;
case 3: cout << "\nAge: "; break;
case 4: cout << "\nEmail: "; break;
case 5: cout << "\nDoor Number: "; break;
case 6: cout << "\nRoad Name: "; break;
case 7: cout << "\nPost Code: "; break;
default:;}
cin >> information[i][j];}
}
void Storage::GetInformation(int i){
// output
i--;
for (int j=0;j<7;j++)
{
switch(j+1)
{case 1: cout << "\nFirst Name: "; break;
case 2: cout << "\nLast Name: "; break;
case 3: cout << "\nAge: "; break;
case 4: cout << "\nEmail: "; break;
case 5: cout << "\nDoor Number: "; break;
case 6: cout << "\nRoad Name: "; break;
case 7: cout << "\nPost Code: "; break;
default:;}
cout << information[i][j];}
}
int main()
{
int x;
Storage();
Storage Someone;
cin >> x;
Someone.SetInformation(int);
return 0;
}
好的,这就是我现在所做的。但是我现在在激活类(class)时遇到问题?我的意思是我不能使用该类或其方法?我是否以正确的方式创建了类?
最佳答案
刚和成员们一起上课firstName
, lastName
等。叫它Person
管他呢。然后用 std::vector<Person>
替换你的数组.
创建从标准输入中读取特定信息的成员方法(可能是一个 enum
告诉方法要读取哪些信息)。
替换 cout
最后用一种方法显示每个对象的信息。
关于c++ - 我如何使用带有类的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14075388/