| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 561 人关注过本帖
标题:按照谭浩强c++第二版敲的代码,居然显示有错,各位能否看一下,谢谢
只看楼主 加入收藏
Vsnow
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:124
专家分:145
注 册:2015-1-3
结帖率:95%
收藏
已结贴  问题点数:10 回复次数:5 
按照谭浩强c++第二版敲的代码,居然显示有错,各位能否看一下,谢谢
程序代码:
#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;
}
2015-06-03 22:55
林月儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:湖南
等 级:版主
威 望:138
帖 子:2277
专家分:10647
注 册:2015-3-19
收藏
得分:2 
void  Student::get_value1()
{
    cin>>num>>name>>sex;
    cin>>age>>addr;
}

剑栈风樯各苦辛,别时冰雪到时春
2015-06-03 23:07
林月儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:湖南
等 级:版主
威 望:138
帖 子:2277
专家分:10647
注 册:2015-3-19
收藏
得分:0 
Student1对,不是Student,sadness

剑栈风樯各苦辛,别时冰雪到时春
2015-06-03 23:08
yangfrancis
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:贵宾
威 望:141
帖 子:1510
专家分:7661
注 册:2014-5-19
收藏
得分:1 
void display1();这个函数和你后面定义的时候拼写有出入。
2015-06-04 23:35
纸T0
Rank: 4
来 自:
等 级:业余侠客
威 望:2
帖 子:34
专家分:216
注 册:2013-11-16
收藏
得分:3 
程序代码:
// 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;
}

2015-06-05 14:22
林月儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:湖南
等 级:版主
威 望:138
帖 子:2277
专家分:10647
注 册:2015-3-19
收藏
得分:4 
程序代码:
#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;
}

剑栈风樯各苦辛,别时冰雪到时春
2015-06-05 14:42
快速回复:按照谭浩强c++第二版敲的代码,居然显示有错,各位能否看一下,谢谢
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.027862 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved