标题:帮忙解决问题
取消只看楼主
晓宁
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2011-9-7
结帖率:71.43%
 问题点数:0 回复次数:0 
帮忙解决问题
#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



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-352949-1-1.html




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

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