第2章第4题

来源:互联网 发布:java架构师证 编辑:程序博客网 时间:2024/06/10 12:36

C++

#include <iostream>#include "student.h"/* run this program using the console pauser or add your own getch, system("pause") or input loop */int main(int argc, char** argv) {student s1;s1.set_value();s1.display();return 0;}

#include "student.h"
<pre name="code" class="cpp">#include <iostream>using namespace std;
void student::display(){cout<<"num="<<num<<endl;cout<<"name="<<name<<endl;cout<<"sex="<<sex<<endl;}void student::set_value(){cin>>num;cin>>name;cin>>sex;}

#ifndef STUDENT_H#define STUDENT_Hclass student{private:int num;string name;char sex;public:void display();void set_value();};#endif


0 0