【发布时间】:2014-09-01 14:00:11
【问题描述】:
#include<iostream>
using namespace std;
class student
{
private:
char name [30], location[50], ic[20];
int age;
public:
void set_data()
{
cout<<"Enter name :";
cin.getline(name, 30);
cout<<"Enter location :";
cin.getline(location, 50);
cout<<"Enter IC :";
cin.getline(ic, 20);
cout<<"Enter age :";
cin>>age;
}
void display()
{
cout<<"Name :"<<name<<endl;
cout<<"IC :"<<ic<<endl;
cout<<"Location :"<<location<<endl;
cout<<"Age :"<<age<<endl;
}
}student s1;
int main()
{
cout<<"--------------------------------"<<endl;
cout<<"WELCOME TO A-PLUS TUITION CENTER"<<endl;
cout<<"--------------------------------"<<endl;
student set_data();
cout<<"--------------------------------"<<endl;
cout<<"STUDENT INFORMATION"<<endl;
cout<<"--------------------------------"<<endl;
student display();
return 0;
}
各位请帮帮我...我被困在这里..我需要这样的输出,但是我在将类调用到主函数时遇到问题..我该怎么办?
--------------------------------
WELCOME TO A-PLUS TUITION CENTER
--------------------------------
Enter Name : Usha Vellappan
Enter Location : Melaka
Enter IC : 750217016680
Enter age : 30
--------------------------------
STUDENT INFOMATION
--------------------------------
Name : Usha Vellappan
IC : 750217016680
Location : Melaka
Age : 30
Press any key to continue
【问题讨论】:
-
有什么问题?它似乎正在工作。
-
初读 OOP 概念。它只是关于创建类的实例并通过这些实例调用方法。先自己试一试
-
我强烈建议你买一本 C++ 书籍并开始阅读。
-
我现在的错误是它的“'s1'之前的预期初始化程序......那么我该如何更改我的代码?
标签: c++ function class object main