| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 510 人关注过本帖
标题:帮忙解决string问题
只看楼主 加入收藏
晓宁
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2011-9-7
结帖率:71.43%
收藏
 问题点数:0 回复次数:1 
帮忙解决string问题
#include<iostream>
#include<string>
using namespace std;
 
class Student
{
protected:
    string name;
    char matric_no[15];
    int status;

public:
    Student()
    {
        cout<<"Calling constructor from the"<<"base class"<<endl;
    }

    void SetData()
    {
        cout<<"Enter name:";
        cin<<name;
        cout<<"Enter matric number:";
        cin<<matric_no;
    }

    virtual void DisplayFees(){};
};

class PartTimeStudent:public Student
{
public:
    PartTimeStudent();
    void DisplayFees();
};

PartTimeStudent::PartTimeStudent()
{
    cout<<"Entering constructor for class"<<"Part Time Student."<<endl;
}

void PartTimeStudent::DisplayFees()
{
    cout<<"Hi,"<<name<<"!";
    cout<<"Your fees is RM300. Thank you."<<endl;
}

class FullTimeStudent:public Student
{
public:
    FullTimeStudent();
    void DisplayFees();
};

FullTimeStudent::FullTimeStudent()
{
    cout<<"Entering constructor for class"<<"Full Time Student."<<endl;
}

void FullTimeStudent::DisplayFees()
{
    cout<<"Hello,"<<name<<"!";
    cout<<"Your fees is RM200. Thank you."<<endl;
}

void main()
{
    FullTimeStudent full_timer;
    full_timer.SetData();
    full_timer.DisplayFees();

    PartTimeStudent part_timer;
    part_timer.SetData();
    part_timer.DisplayFees();
}
搜索更多相关主题的帖子: include public number status Enter 
2011-10-17 20:57
kscooh1
Rank: 2
等 级:论坛游民
帖 子:53
专家分:25
注 册:2011-8-8
收藏
得分:0 
回复 楼主 晓宁
楼主要仔细呀,看清楚,头文件using namespace std; 这个分号有问题;
还有cin后面是>>不是<< .要仔细。。
下面程序都可以运行了:
#include<iostream>
#include<string>
using namespace std;

class Student
{
protected:
    string name;
    char matric_no[15];
    int status;

public:
    Student()
    {
        cout<<"Calling constructor from the"<<"base class"<<endl;
    }

    void SetData()
    {
        cout<<"Enter name:";
        cin>>name;
        cout<<"Enter matric number:";
        cin>>matric_no;
    }

    virtual void DisplayFees(){};
};

class PartTimeStudent:public Student
{
public:
    PartTimeStudent();
    void DisplayFees();
};

PartTimeStudent::PartTimeStudent()
{
    cout<<"Entering constructor for class"<<"Part Time Student."<<endl;
}

void PartTimeStudent::DisplayFees()
{
    cout<<"Hi,"<<name<<"!";
    cout<<"Your fees is RM300. Thank you."<<endl;
}

class FullTimeStudent:public Student
{
public:
    FullTimeStudent();
    void DisplayFees();
};

FullTimeStudent::FullTimeStudent()
{
    cout<<"Entering constructor for class"<<"Full Time Student."<<endl;
}

void FullTimeStudent::DisplayFees()
{
    cout<<"Hello,"<<name<<"!";
    cout<<"Your fees is RM200. Thank you."<<endl;
}

void main()
{
    FullTimeStudent full_timer;
    full_timer.SetData();
    full_timer.DisplayFees();

    PartTimeStudent part_timer;
    part_timer.SetData();
    part_timer.DisplayFees();
}

运行:
--------------------Configuration: string - Win32 Debug--------------------
Linking...

string.exe - 0 error(s), 0 warning(s)
2011-10-17 23:41
快速回复:帮忙解决string问题
数据加载中...
 
   



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

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