04737 c++程序设计 第二章 课后程序设计题 第一题

/*
*	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();
} 
  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值