定義一個學生結構體student,包括學生的學號,姓名,性別和出生日期,出生日期要求,包括年月日撰寫程式,輸出一個學生的所有資訊。
uj5u.com熱心網友回復:
#include<iostream>
using namespace std;
class Student
{
public:
int id;
string name;
string sex;
string birthday;
Student(int i, string n, string s, string bir)
{
id = i;
name = n;
sex = s;
birthday = bir;
}
void show()
{
cout << "id :" << id << endl;
cout << "name: " << name << endl;
cout << "sex : " << sex << endl;
cout << "birthday: " << birthday << endl;
}
};
int main()
{
Student s(001,"Michael","man","19XX-XX-XX");
s.show();
return 0;
}
id :1
name: Michael
sex : man
birthday: 19XX-XX-XX
Process finished with exit code 0
uj5u.com熱心網友回復:
結構體,結構體,結構體
是struct 不是 class
代碼同上,把class 改成 struct,其他不動
uj5u.com熱心網友回復:
參考 2 樓 尋開心的回復: 結構體,結構體,結構體
是struct 不是 class
代碼同上,把class 改成 struct,其他不動
謝謝????????
uj5u.com熱心網友回復:
參考 1 樓 Michael阿明的回復: #include<iostream>
using namespace std;
class Student
{
public:
int id;
string name;
string sex;
string birthday;
Student(int i, string n, string s, string bir)
{
id = i;
name = n;
sex = s;
birthday = bir;
}
void show()
{
cout << "id :" << id << endl;
cout << "name: " << name << endl;
cout << "sex : " << sex << endl;
cout << "birthday: " << birthday << endl;
}
};
int main()
{
Student s(001,"Michael","man","19XX-XX-XX");
s.show();
return 0;
}
id :1
name: Michael
sex : man
birthday: 19XX-XX-XX
Process finished with exit code 0
多謝啦!!!
uj5u.com熱心網友回復:
參考 4 樓 zxr_jwbq的回復: Quote: 參考 1 樓 Michael阿明的回復: #include<iostream>
using namespace std;
class Student
{
public:
int id;
string name;
string sex;
string birthday;
Student(int i, string n, string s, string bir)
{
id = i;
name = n;
sex = s;
birthday = bir;
}
void show()
{
cout << "id :" << id << endl;
cout << "name: " << name << endl;
cout << "sex : " << sex << endl;
cout << "birthday: " << birthday << endl;
}
};
int main()
{
Student s(001,"Michael","man","19XX-XX-XX");
s.show();
return 0;
}
id :1
name: Michael
sex : man
birthday: 19XX-XX-XX
Process finished with exit code 0
多謝啦!!!
不客氣啦
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/130851.html
標籤:C++ 語言
上一篇:c語言小白 求解題
下一篇:菜鳥自學c入門,求大神解答一下困惑