/*
* 04737 c++ 自学考试2019版 第二章课后练习
* 程序设计题 1
* 需求:设计并实现一个类Course.它代表学校中的一门课程.....
*/
//标准流
#include<iostream>
//标准字符
#include<string>
using namespace std;
class Course{
private:
//课程名
string courseName;
//学分
int score;
//学时数
int hours;
//课程类别
string category;
//授课专业
string professional;
public:
//无参构造器
Course();
//有参构造器
Course(string courseName,string category,string professional,int score,int hours);
//声明getter
string getCourseName();
string getCategory();
string getProfessional();
int getScore();
int getHours();
//声明setter
void setCourseName(string str);
void setCategory(string str);
void setProfessional(string str);
void setScore(int a);
void setHours(int a);
//声明 打印所有数据函数
void showInfo();
};
//定义无参构造
Course::Course()
{
cout<<"The no-argument constructor is running"<<endl;
}
//定义有参构造
Course::Course(string courseName_,string category_,string professional_,int score_,int hours_)
{
courseName = courseName_;
category = category_;
professional = professional_;
score = score_;
hours = hours_;
}
//定义 getter
string Course::getCourseName(){return courseName;}
string Course::getCategory(){return category;}
string Course::getProfessional(){return professional;}
int Course::getScore(){return score;}
int Course::getHours(){return hours;}
//定义 setter
void Course::setCourseName(string str){courseName = str;}
void Course::setCategory(string str){category = str;}
void Course::setProfessional(string str){professional = str;}
void Course::setScore(int a){score = a;}
void Course::setHours(int a){hours = a;}
//定义 打印所有数据函数
void Course::showInfo()
{
cout<<"print all the infomation"<<endl;
cout<<"courseName="<<courseName<<endl;
cout<<"category="<<category<<endl;
cout<<"professional="<<professional<<endl;
cout<<"score="<<score<<endl;
cout<<"hours="<<hours<<endl;
}
//主函数测试
int main()
{
Course test("c++程序设计","c++","计算机科学技术",80,60);
test.showInfo();
}
04737 c++程序设计 第二章 课后程序设计题 第一题
最新推荐文章于 2022-11-18 13:41:02 发布