源程序:
#include <iostream>
#include <string>
using namespace std;
class Course
{
private:
string coursename;
int credit;
int xueshi;
string type;
string profession;
public:
Course(string coursename1, int credit1, int xueshi1, string type1, string profession1)
{
coursename = coursename1;
credit = credit1;
xueshi = xueshi1;
type = type1;
profession = profession1;
}
string get_coursename()
{
return coursename;
}
int get_credit()
{
return credit;
}
int get_xueshi()
{
return xueshi;
}
string get_type()
{
return type;
}
string get_profession()
{
return profession;
}
};
int main()
{
Course course("网络实训",4,4,"专业课","计算机网络");
cout << "我叫李明"<<endl<<"本学期计算机网络只学一门专业课" << endl;
cout << "课程名称是:";
cout <<"《"<< course.get_coursename()<<"》"<<endl;
cout<<"学分为:"<<course.get_credit()<<endl;
system("pause");
return 1;
}
运行结果: