注册 登录
编程论坛 C++教室

按照谭浩强c++第二版敲的代码,居然显示有错,各位能否看一下,谢谢

Vsnow 发布于 2015-06-03 22:55, 561 次点击
程序代码:
#include <iostream>
#include <string>
using namespace std;
class Student
{
public:
protected:
    int num;
    string name;
    char sex;
};
class Student1:protected Student
{
public:
    void get_value1();
    void display1();
private:
    int age;
    string addr;
};
void  get_value1()
{a
    cin>>num>>name>>sex;
    cin>>age>>addr;
}
void Student1::dispaly1()
{
    cout<<"name"<<name<<endl;
    cout<<"num"<<num<<endl;
    cout<<"sex"<<sex<<endl;
    cout<<"age"<<age<<endl;
    cout<<"address"<<addr<<endl;
}
int main()
{
    Student1 stud1;
    stud1.get_value1();
    stud1.display1();
    return 0;
}
5 回复
#2
林月儿2015-06-03 23:07
void  Student::get_value1()
{
    cin>>num>>name>>sex;
    cin>>age>>addr;
}
#3
林月儿2015-06-03 23:08
Student1对,不是Student,sadness
#4
yangfrancis2015-06-04 23:35
void display1();这个函数和你后面定义的时候拼写有出入。
#5
纸T02015-06-05 14:22
程序代码:
// test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
class Student
{
public:
protected:
    int num;
    string name;
    char sex;
};
class Student1:protected Student
{
public:
    void get_value1();
    void display1();
private:
    int age;
    string addr;
};
void  Student1::get_value1()
{
    cin>>num>>name>>sex;
    cin>>age>>addr;
}
void Student1::display1()
{
    cout<<"name"<<name<<endl;
    cout<<"num"<<num<<endl;
    cout<<"sex"<<sex<<endl;
    cout<<"age"<<age<<endl;
    cout<<"address"<<addr<<endl;
}
int main()
{
    Student1 stud1;
    stud1.get_value1();
    stud1.display1();
    return 0;
}
#6
林月儿2015-06-05 14:42
程序代码:
#include <iostream>
#include <string>
using namespace std;
class Student{
protected:
    int num;
    string name;
    char sex;
};
class Student1:protected Student{
public:
    void get_value1();
    void display1();
private:
    int age;
    string addr;
};
void  Student1::get_value1(){
    cout<<"num:";    cin>>num;
    cout<<"name:";   cin>>name;
    cout<<"sex:";    cin>>sex;
    cout<<"age:";    cin>>age;
    cout<<"addr:";   cin>>addr;
}
void Student1::display1(){
    cout<<"name"<<name<<endl;
    cout<<"num"<<num<<endl;
    cout<<"sex"<<sex<<endl;
    cout<<"age"<<age<<endl;
    cout<<"address"<<addr<<endl;
}
int main(){
    Student1 stud1;
    stud1.get_value1();
    stud1.display1();
    return 0;
}
1