程序运行不出来_运行不出来,如何改?

原问题:运行不出来,如何改?
分类:编程开发 > 最后更新时间:【2016-12-15 02:00:52】
问题补充:

#include<iostream.h>

Class Student

{public:

void get_value()

{

cin>>num>>name>>sex;

}

void display()

{

cout<<"num:"<<num<<endl;

cout<<"name:"<<name<<endl;

cout<<"sex:"<<sex<<endl;

}

private:

int num;

string name;

char sex;

};

Class Student1:private Student

{public:

void get_value_1()

{cin>>num>>name>>sex;}

void display_1()

{

cout<<"age:"<<age<<endl;

cout<<"address:"<<adrr<<endl;

private:

int age;

string sddr;

};

int main()

{Student1 stud1;

stud1.get_vaule-1();

stud1.display_1();

return 0;

}

最佳答案

你这些代码如果能编译通过,我也服了你了。随便列举下书写及语法错误吧

1、Class居然是首字母大写

2、stud1.get_vaule-1()这用法也没谁了,书写不准确

3、string也没有包含头文件,没有使用命名空间

4、cout及cin也不能这样使用,需要使用命名空间。

5、display_1()函数少了一个右大括号

6、display_1()函数中的addr没有定义

7、Student1类中的get_value_1()方法如何访问父类中的私有成员

追答:
仅仅是随便列几个,至于其它的语法及习惯等,问题还有很多
追问:
#include <iostream.h>class Student{ public: void get_value(); void display();protected: int num; string name; char sex;};void Student :: get_value(){ cin >> num >> name >> sex;}void Student :: display(){ cout << "num:" << num << endl; cout << "name:" << name << endl; cout << "sex:" << sex << endl;}class Student1:protected Student{ public: void display_1(); void get_value1(); private: int age; string addr;};void Student1 :: display_1(){ cout << "num:" << num << endl; cout << "name:" << name << endl; cout << "sex:" << sex << endl; cout << "age:" << age << endl; cout << "address:" << addr << endl;}void Student1 :: get_value1(){ cin >> num >> name >> sex >> age >> addr;}int main(){ Student1 stu; stu.get_value1(); stu.display_1(); system("pause"); return 0;}
  • 追答:
    1、string需要包含头文件2、使用cin、cout及string需要使用std命名空间可以在#include <iostream>后面加上两行#include <string>using namespace std;
    最佳答案由网友  听枫2005  提供
  • 公告: 为响应国家净网行动,部分内容已经删除,感谢网友理解。
    4

    分享到:

    其他回答

    暂无其它回答!

      推荐