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

class CollegeCourse
{
protected:
    string department_name;
    string course_id;
    int credit_hour;
    float tuition_fee;
    void ShowProperties();

public:
    CollegeCourse(){};
    void SetProperties(string i_department_name,string i_course_id,
                        int i_credit_hour,float i_tuition_fee);
};

void CollegeCourse::SetProperties(string i_department_name,string i_course_id,
                                  int i_credit_hour,float i_tuition_fee)
{
    department_name=i_department_name;
    course_id=i_course_id;
    credit_hour=i_credit_hour;
    tuition_fee=i_tuition_fee;
}

void CollegeCourse::ShowProperties()
{
    cout<<"Department:"<<department_name<<endl;
    cout<<"Course:"<<course_id<<endl;
    cout<<"Credit Hour:"<<credit_hour<<endl;
    cout<<"Tuition Fee:"<<tuition_fee<<endl;
}

class LabCourse:public CollegeCourse
{
private:
    float lab_fee;
public:
    LabCourse(){};

    //overloading the function with the same name in the base class
    void SetProperties(string i_department_name,string i_course_id,int i_credit_hour,
                       float i_tuition_fee,float i_lab_fee);

    //overiding the protected access control
    CollegeCourse::ShowProperties;
};

void LabCourse::SetProperties(string i_department_name,string i_course_id,int i_credit_hour,
                              float i_tuition_fee,float i_lab_fee)
{
    //overriding a function with similar name but in the base class
    CollegeCourse::SetProperties(i_department_name,i_course_id,i_credit_hour,
                                 i_tuition_fee);
    lab_fee=i_lab_fee;
}

void main()
{
    CollegeCourse my_college;
    my_college.SetProperties("JTMK","F3031",4,200);
    LabCourse my_lab;
    my_lab.SetProperties("JTMK","F3031",4,200,100);
    my_lab.ShowProperties();
}



搜索更多相关主题的帖子: include public class using 
2011-10-19 22:04
czsbc
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
帖 子:469
专家分:1700
注 册:2008-12-13
收藏
得分:0 
有啥问题
2011-10-19 22:40
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9007
专家分:53942
注 册:2011-1-18
收藏
得分:0 
以下是引用czsbc在2011-10-19 22:40:06的发言:

有啥问题
逗你玩儿呢
2011-10-20 08:13
快速回复:帮忙解决问题
数据加载中...
 
   



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

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