用C++编写一个综合程序,急用!!!
一、实验目的检验对面向对象中的封装,继承,多态等知识的理解和掌握情况,综合考察利用面向对象知识模拟现实世界活动的能力。二、实验内容与要求实验内容要求:1.自选题目;2.使...
一、实验目的
检验对面向对象中的封装,继承,多态等知识的理解和掌握情况,综合考察利用面向对象知识模拟现实世界活动的能力。
二、实验内容与要求
实验内容要求:1.自选题目;2.使用面向对象编程技术,设计一个系统;3系统中至少要包含5个类;4.要使用到封装,继承,多态,运算符重载等面向对象的主要技术。
程序编写要求:1.建立Win32 Console Application工程;2.使用接口与实现分离的技术处理头文件与源文件;3. main函数位于单独的文件中,程序可以正常运行并输出结果。
三、实验方案与步骤
(1.分析阶段:分析题目,根据系统需求,应设计的类和相应的功能接口,写出思路和分析的过程;2.设计阶段:给出设计方案,类的设计,类图绘制,类之间的继承关系图等相关图表;3.编码阶段:根据设计方案,编写代码;4.调试运行阶段:对系统进行调试,修正错误,得到正确的运行结果) 展开
检验对面向对象中的封装,继承,多态等知识的理解和掌握情况,综合考察利用面向对象知识模拟现实世界活动的能力。
二、实验内容与要求
实验内容要求:1.自选题目;2.使用面向对象编程技术,设计一个系统;3系统中至少要包含5个类;4.要使用到封装,继承,多态,运算符重载等面向对象的主要技术。
程序编写要求:1.建立Win32 Console Application工程;2.使用接口与实现分离的技术处理头文件与源文件;3. main函数位于单独的文件中,程序可以正常运行并输出结果。
三、实验方案与步骤
(1.分析阶段:分析题目,根据系统需求,应设计的类和相应的功能接口,写出思路和分析的过程;2.设计阶段:给出设计方案,类的设计,类图绘制,类之间的继承关系图等相关图表;3.编码阶段:根据设计方案,编写代码;4.调试运行阶段:对系统进行调试,修正错误,得到正确的运行结果) 展开
展开全部
一、实验目的
检验对面向对象中的封装,继承,多态等知识的理解和掌握情况,综合考察利用面向对腊隐灶象知识模拟现实世界活动的能力。
二、实验内容与要求
实验内容要求:1.自选题目;2.使用面向对象编程技术,设计一个系统;3系统中至少要包含5个类;4.要使用到封装,继承,多态,运算符重载等面向对象的主要技术。
程序编写要求:1.建立Win32 Console Application工程;2.使用接口与实现分离的技术处理头文件与源文件;3. main函数位于单独的文件中,程序可以正常运行并输出结果。
三、实验方案与步骤
1.分析阶段:
问题的描述(功能要求):
现一高校有四类人员:教授,学生,行政人员,行政人员兼职教授。为了实现工资发放的自动结算功能,现要求编写程序来自动完成此功能。
相关信息:
每一学期将学校职工的本学期任职情况及上学期工作的相关情况输入计算机,则本学期职工的月工资按程序处理后的结果发放,其中职工的工资计算方法如下:
其中工资的基本构成如下:
教授: 基本工资+课时费;
学生: 书费;
行政人员: 基本工资+行政补贴;
行政人员兼职教授:基本工资+行政补贴+课时费
2.设计阶段:
1)、设计方案:
改系统有 工作者,学生,教授,行政人员,行政人员兼教授五大类组成
基类:worker包含 firstname,lastname,socialsecuritynumber三个数据成员作为其属性轮扮。相应的接口为:setfirstname(&first)对firstname进行赋值,Getfirstname()返回firstname;setlastname(&last)对lastname进行赋值,setssn(&ssn)对socialsecuritynumber进行赋值,getSSN返回socialsecuritynumber,虚函数print()输出其信息,纯虚函数earning()用来计算工资。
派生类:
a):派生类student继承类基类firstname,lastname,socialsecuritynumber的属性,并有fee 作为自己的生活费。
b): 派生类professor公携态有继承了worker的属性,并有worketime 作为自己的工作时间,还有静态变量 basesalary,CommissionRate作为每一个对象都有的基本工资和提成率。
c): 派生类Administrator公有继承了worker的属性,并有outday作为出差时间,作为行政补贴的度量,还有静态变量 basesalary,CommissionRate作为每一个对象都有的基本工资和提成率。
d): 派生类Manager公有继承了professor和Administrator的属性,并有worketime和outday 作为自己的工作时间,还有静态变量 basesalary,CommissionRate作为每一个对象都有的基本工资和提成率。
类视图:
Worker Student
string FirstName;
string LastName;
string SocialSecurityNumber; Public:worker
double Fee
+worker();
+worker(const string & ,const string &,const string &);
~worker();
+void SetFirstname(const string &);
+string GetFirstname()const;
+void SetLastname(const string &);
+string GetLastname()const;
+ void SetSSN(const string &);
+string GetSSN() const;
+virtual double earning() const =0;
+virtual void print() const; + double GetFee() const
Professor Administrator
Public:worker
static double BaseSalary ;
static double CommissionRate ;
int WorkTime; Public:worker
static double BaseSalary;
static double CommissionRate;
int Outday;
+void SetWorktime(int);
+int GetWorktime();
+void SetCommissionrate();
+double GetBasesalary();
~Professor(void);
+double Blus () const;
Administrator();
+Administrator(const string &,const string &,const string &,int =0);
+double GetBasesalary();
+void SetOutday(int);
+int GetOutday();
+double Blus() const;
~Administrator(void);
Manager
public Professor
public Administrator
Manager();
Manager(const string&,const string &,const string &,int = 0,int = 0);
virtual double earning() const;
virtual void print() const;
~Manager(void);
类的继承关系图:
worker
Student Professor Administrator
Manager
3.编码阶段:根据设计方案,编写代码
#include<iostream>
#include <string>
#pragma once
using std::string;
using std::cout;
using std::endl;
class worker
{
public:
worker();
worker(const string & ,const string &,const string &);
~worker();
void SetFirstname(const string &);
string GetFirstname()const;
void SetLastname(const string &);
string GetLastname()const;
void SetSSN(const string &);
string GetSSN() const;
virtual double earning() const =0;
virtual void print() const;
private:
string FirstName;
string LastName;
string SocialSecurityNumber;
};
#include "worker.h"
#include<iostream>
using std::cout;
using std::endl;
worker::worker()
{
FirstName = "a";
LastName = "b";
string SocialSecurityNumber="0";
}
worker::worker(const string &first,const string &last,const string &ssn)
:FirstName(first),LastName(last),SocialSecurityNumber(ssn)
{
}
void worker::SetFirstname(const string &first)
{
FirstName = first;
}
string worker::GetFirstname()const
{
return FirstName;
}
void worker::SetLastname(const string &last)
{
LastName=last;
}
string worker::GetLastname()const
{
return LastName;
}
void worker::SetSSN(const string &ssn)
{
SocialSecurityNumber=ssn;
}
string worker::GetSSN()const
{
return SocialSecurityNumber;
}
void worker::print() const
{
cout<<GetFirstname()<<' '<<GetLastname()
<<"\nSocial Security Number"<<GetSSN()<<endl;
}
worker::~worker(void)
{
}
#include"worker.h"
class Student:public worker
{
public:
Student();
Student(const string &,const string &,const string &);
double GetFee() const;
~Student(void);
virtual double earning() const;
virtual void print() const;
private:
static double Fee;
};
#include "Student.h"
using std::cout;
using std::endl;
double Student::Fee = 800.0;
Student::Student(const string &first,const string &last,const string &ssn)
:worker(first,last,ssn)
{
}
Student::Student()
{
SetFirstname ("a");
SetLastname ("b");
SetSSN("0");
}
double Student::GetFee()const
{
return Fee;
}
void Student::print() const
{
worker::print();
cout<<"This member is a student"<<
" He must cost "<<GetFee()<<" erery month"<<endl;
}
double Student::earning() const
{
return GetFee();
}
Student::~Student(void)
{
}
#pragma once
#include "worker.h"
class Professor :
public worker
{
public:
Professor();
Professor(const string&,const string &,const string &,int =0);
void SetWorktime(int);
int GetWorktime();
void SetCommissionrate();
double GetBasesalary();
~Professor(void);
double Blus () const;
virtual double earning() const;
virtual void print() const;
private:
static double BaseSalary ;
static double CommissionRate ;
int WorkTime;
};
#include "Professor.h"
double Professor::CommissionRate = 20.0;
double Professor::BaseSalary = 1800;
Professor::Professor(const string &first,const string &last,const string &ssn,int worktime)
:worker(first,last,ssn)
{
SetWorktime(worktime);
}
Professor::Professor()
{
SetFirstname ("a");
SetLastname ("b");
SetSSN("0");
SetWorktime(0);
}
double Professor::GetBasesalary()
{
return BaseSalary;
}
double Professor::Blus() const
{
return (WorkTime -10)*CommissionRate;
}
void Professor::SetWorktime(int worktime)
{
WorkTime =worktime;
}
int Professor::GetWorktime()
{
return WorkTime;
}
double Professor::earning()const
{
return BaseSalary +Blus();
}
void Professor::print()const
{
worker::print();
cout<<"Earnings:"<<earning()<<endl;
}
Professor::~Professor(void)
{
}
#include"worker.h"
#include"Professor.h"
#include<iostream>
#pragma once
class Administrator:public worker
{
public:
Administrator();
Administrator(const string &,const string &,const string &,int =0);
double GetBasesalary();
void SetOutday(int);
int GetOutday();
double Blus() const;
~Administrator(void);
virtual double earning() const;
virtual void print() const;
private:
static double BaseSalary;
static double CommissionRate;
int Outday;
};
#include "Administrator.h"
using std::cout;
using std::endl;
#include<iostream>
double Administrator::BaseSalary = 2000.0;
double Administrator::CommissionRate = 200.0;
Administrator::Administrator(const string &first,const string &last,const string &ssn,int outday )
:worker(first,last,ssn)
{
SetOutday(outday);
}
Administrator::Administrator()
{
SetFirstname ("a");
SetLastname ("b");
SetSSN("0");
SetOutday(0);
}
double Administrator::GetBasesalary()
{
return BaseSalary;
}
double Administrator::Blus() const
{
return Outday*CommissionRate;
}
Administrator::~Administrator(void)
{
}
void Administrator::SetOutday(int worktime)
{
Outday =worktime;
}
int Administrator::GetOutday()
{
return Outday;
}
double Administrator::earning()const
{
return BaseSalary + Blus();
}
void Administrator::print()const
{
worker::print();
cout<<"Earnings:"<<earning()<<endl;
}
#include "professor.h"
#include"Administrator.h"
#pragma once
class Manager :
public Professor ,public Administrator
{
public:
Manager();
Manager(const string&,const string &,const string &,int = 0,int = 0);
virtual double earning() const;
virtual void print() const;
~Manager(void);
private:
string FirstName;
string LastName;
string SocialSecurityNumber;
static double BaseSalary;
};
#include "Manager.h"
double Manager::BaseSalary = 2200.0;
Manager::Manager(const string &first,const string &last,const string &ssn,int outday ,int worktime)
:Professor(first,last,ssn,worktime),Administrator(first,last,ssn,outday)
{
this->FirstName = first;
this->LastName =last;
this ->SocialSecurityNumber = ssn;
}
Manager::Manager()
{
Professor::SetFirstname ("a");
Professor::SetLastname ("b");
Professor::SetSSN("0");
Professor::SetWorktime(0);
Administrator::SetOutday(0);
}
Manager::~Manager(void)
{
}
double Manager::earning()const
{
return BaseSalary +Professor::Blus()+Administrator::Blus();
}
void Manager::print() const
{
cout<<FirstName<<' '<<LastName
<<"\nSocial Security Number"<<SocialSecurityNumber<<endl;
cout<<"Earnings:"<<earning()<<endl;
}
#include"Manager.h"
#include"Student.h"
#include"Administrator.h"
#include<iostream>
using std::cout;
using std::endl;
using std::cin;
#include<vector>
using std::vector;
void pointer( worker const *ptr )
{
ptr->print();
}
int main()
{
Professor a("zhang","san","1",15);
Administrator b("li","si","2",20);
Manager c ("wang","wu","3",15,20);
Student d("wang","liu","4");
vector<worker*>member(4);
member[0] = &a;
member[1] = &b;
member[2] =dynamic_cast<Professor *>(&c);
member[3] = &d;
for(size_t i =0;i<member.size();i++)
pointer(member[i]);
return 0;
}
4.调试运行阶段:
member[2] =&c,此语句错误,提示为:worker类不明确,要将Manager向上转型为Professor或者Administrator
member[2] =dynamic_cast<Professor *>(&c)
检验对面向对象中的封装,继承,多态等知识的理解和掌握情况,综合考察利用面向对腊隐灶象知识模拟现实世界活动的能力。
二、实验内容与要求
实验内容要求:1.自选题目;2.使用面向对象编程技术,设计一个系统;3系统中至少要包含5个类;4.要使用到封装,继承,多态,运算符重载等面向对象的主要技术。
程序编写要求:1.建立Win32 Console Application工程;2.使用接口与实现分离的技术处理头文件与源文件;3. main函数位于单独的文件中,程序可以正常运行并输出结果。
三、实验方案与步骤
1.分析阶段:
问题的描述(功能要求):
现一高校有四类人员:教授,学生,行政人员,行政人员兼职教授。为了实现工资发放的自动结算功能,现要求编写程序来自动完成此功能。
相关信息:
每一学期将学校职工的本学期任职情况及上学期工作的相关情况输入计算机,则本学期职工的月工资按程序处理后的结果发放,其中职工的工资计算方法如下:
其中工资的基本构成如下:
教授: 基本工资+课时费;
学生: 书费;
行政人员: 基本工资+行政补贴;
行政人员兼职教授:基本工资+行政补贴+课时费
2.设计阶段:
1)、设计方案:
改系统有 工作者,学生,教授,行政人员,行政人员兼教授五大类组成
基类:worker包含 firstname,lastname,socialsecuritynumber三个数据成员作为其属性轮扮。相应的接口为:setfirstname(&first)对firstname进行赋值,Getfirstname()返回firstname;setlastname(&last)对lastname进行赋值,setssn(&ssn)对socialsecuritynumber进行赋值,getSSN返回socialsecuritynumber,虚函数print()输出其信息,纯虚函数earning()用来计算工资。
派生类:
a):派生类student继承类基类firstname,lastname,socialsecuritynumber的属性,并有fee 作为自己的生活费。
b): 派生类professor公携态有继承了worker的属性,并有worketime 作为自己的工作时间,还有静态变量 basesalary,CommissionRate作为每一个对象都有的基本工资和提成率。
c): 派生类Administrator公有继承了worker的属性,并有outday作为出差时间,作为行政补贴的度量,还有静态变量 basesalary,CommissionRate作为每一个对象都有的基本工资和提成率。
d): 派生类Manager公有继承了professor和Administrator的属性,并有worketime和outday 作为自己的工作时间,还有静态变量 basesalary,CommissionRate作为每一个对象都有的基本工资和提成率。
类视图:
Worker Student
string FirstName;
string LastName;
string SocialSecurityNumber; Public:worker
double Fee
+worker();
+worker(const string & ,const string &,const string &);
~worker();
+void SetFirstname(const string &);
+string GetFirstname()const;
+void SetLastname(const string &);
+string GetLastname()const;
+ void SetSSN(const string &);
+string GetSSN() const;
+virtual double earning() const =0;
+virtual void print() const; + double GetFee() const
Professor Administrator
Public:worker
static double BaseSalary ;
static double CommissionRate ;
int WorkTime; Public:worker
static double BaseSalary;
static double CommissionRate;
int Outday;
+void SetWorktime(int);
+int GetWorktime();
+void SetCommissionrate();
+double GetBasesalary();
~Professor(void);
+double Blus () const;
Administrator();
+Administrator(const string &,const string &,const string &,int =0);
+double GetBasesalary();
+void SetOutday(int);
+int GetOutday();
+double Blus() const;
~Administrator(void);
Manager
public Professor
public Administrator
Manager();
Manager(const string&,const string &,const string &,int = 0,int = 0);
virtual double earning() const;
virtual void print() const;
~Manager(void);
类的继承关系图:
worker
Student Professor Administrator
Manager
3.编码阶段:根据设计方案,编写代码
#include<iostream>
#include <string>
#pragma once
using std::string;
using std::cout;
using std::endl;
class worker
{
public:
worker();
worker(const string & ,const string &,const string &);
~worker();
void SetFirstname(const string &);
string GetFirstname()const;
void SetLastname(const string &);
string GetLastname()const;
void SetSSN(const string &);
string GetSSN() const;
virtual double earning() const =0;
virtual void print() const;
private:
string FirstName;
string LastName;
string SocialSecurityNumber;
};
#include "worker.h"
#include<iostream>
using std::cout;
using std::endl;
worker::worker()
{
FirstName = "a";
LastName = "b";
string SocialSecurityNumber="0";
}
worker::worker(const string &first,const string &last,const string &ssn)
:FirstName(first),LastName(last),SocialSecurityNumber(ssn)
{
}
void worker::SetFirstname(const string &first)
{
FirstName = first;
}
string worker::GetFirstname()const
{
return FirstName;
}
void worker::SetLastname(const string &last)
{
LastName=last;
}
string worker::GetLastname()const
{
return LastName;
}
void worker::SetSSN(const string &ssn)
{
SocialSecurityNumber=ssn;
}
string worker::GetSSN()const
{
return SocialSecurityNumber;
}
void worker::print() const
{
cout<<GetFirstname()<<' '<<GetLastname()
<<"\nSocial Security Number"<<GetSSN()<<endl;
}
worker::~worker(void)
{
}
#include"worker.h"
class Student:public worker
{
public:
Student();
Student(const string &,const string &,const string &);
double GetFee() const;
~Student(void);
virtual double earning() const;
virtual void print() const;
private:
static double Fee;
};
#include "Student.h"
using std::cout;
using std::endl;
double Student::Fee = 800.0;
Student::Student(const string &first,const string &last,const string &ssn)
:worker(first,last,ssn)
{
}
Student::Student()
{
SetFirstname ("a");
SetLastname ("b");
SetSSN("0");
}
double Student::GetFee()const
{
return Fee;
}
void Student::print() const
{
worker::print();
cout<<"This member is a student"<<
" He must cost "<<GetFee()<<" erery month"<<endl;
}
double Student::earning() const
{
return GetFee();
}
Student::~Student(void)
{
}
#pragma once
#include "worker.h"
class Professor :
public worker
{
public:
Professor();
Professor(const string&,const string &,const string &,int =0);
void SetWorktime(int);
int GetWorktime();
void SetCommissionrate();
double GetBasesalary();
~Professor(void);
double Blus () const;
virtual double earning() const;
virtual void print() const;
private:
static double BaseSalary ;
static double CommissionRate ;
int WorkTime;
};
#include "Professor.h"
double Professor::CommissionRate = 20.0;
double Professor::BaseSalary = 1800;
Professor::Professor(const string &first,const string &last,const string &ssn,int worktime)
:worker(first,last,ssn)
{
SetWorktime(worktime);
}
Professor::Professor()
{
SetFirstname ("a");
SetLastname ("b");
SetSSN("0");
SetWorktime(0);
}
double Professor::GetBasesalary()
{
return BaseSalary;
}
double Professor::Blus() const
{
return (WorkTime -10)*CommissionRate;
}
void Professor::SetWorktime(int worktime)
{
WorkTime =worktime;
}
int Professor::GetWorktime()
{
return WorkTime;
}
double Professor::earning()const
{
return BaseSalary +Blus();
}
void Professor::print()const
{
worker::print();
cout<<"Earnings:"<<earning()<<endl;
}
Professor::~Professor(void)
{
}
#include"worker.h"
#include"Professor.h"
#include<iostream>
#pragma once
class Administrator:public worker
{
public:
Administrator();
Administrator(const string &,const string &,const string &,int =0);
double GetBasesalary();
void SetOutday(int);
int GetOutday();
double Blus() const;
~Administrator(void);
virtual double earning() const;
virtual void print() const;
private:
static double BaseSalary;
static double CommissionRate;
int Outday;
};
#include "Administrator.h"
using std::cout;
using std::endl;
#include<iostream>
double Administrator::BaseSalary = 2000.0;
double Administrator::CommissionRate = 200.0;
Administrator::Administrator(const string &first,const string &last,const string &ssn,int outday )
:worker(first,last,ssn)
{
SetOutday(outday);
}
Administrator::Administrator()
{
SetFirstname ("a");
SetLastname ("b");
SetSSN("0");
SetOutday(0);
}
double Administrator::GetBasesalary()
{
return BaseSalary;
}
double Administrator::Blus() const
{
return Outday*CommissionRate;
}
Administrator::~Administrator(void)
{
}
void Administrator::SetOutday(int worktime)
{
Outday =worktime;
}
int Administrator::GetOutday()
{
return Outday;
}
double Administrator::earning()const
{
return BaseSalary + Blus();
}
void Administrator::print()const
{
worker::print();
cout<<"Earnings:"<<earning()<<endl;
}
#include "professor.h"
#include"Administrator.h"
#pragma once
class Manager :
public Professor ,public Administrator
{
public:
Manager();
Manager(const string&,const string &,const string &,int = 0,int = 0);
virtual double earning() const;
virtual void print() const;
~Manager(void);
private:
string FirstName;
string LastName;
string SocialSecurityNumber;
static double BaseSalary;
};
#include "Manager.h"
double Manager::BaseSalary = 2200.0;
Manager::Manager(const string &first,const string &last,const string &ssn,int outday ,int worktime)
:Professor(first,last,ssn,worktime),Administrator(first,last,ssn,outday)
{
this->FirstName = first;
this->LastName =last;
this ->SocialSecurityNumber = ssn;
}
Manager::Manager()
{
Professor::SetFirstname ("a");
Professor::SetLastname ("b");
Professor::SetSSN("0");
Professor::SetWorktime(0);
Administrator::SetOutday(0);
}
Manager::~Manager(void)
{
}
double Manager::earning()const
{
return BaseSalary +Professor::Blus()+Administrator::Blus();
}
void Manager::print() const
{
cout<<FirstName<<' '<<LastName
<<"\nSocial Security Number"<<SocialSecurityNumber<<endl;
cout<<"Earnings:"<<earning()<<endl;
}
#include"Manager.h"
#include"Student.h"
#include"Administrator.h"
#include<iostream>
using std::cout;
using std::endl;
using std::cin;
#include<vector>
using std::vector;
void pointer( worker const *ptr )
{
ptr->print();
}
int main()
{
Professor a("zhang","san","1",15);
Administrator b("li","si","2",20);
Manager c ("wang","wu","3",15,20);
Student d("wang","liu","4");
vector<worker*>member(4);
member[0] = &a;
member[1] = &b;
member[2] =dynamic_cast<Professor *>(&c);
member[3] = &d;
for(size_t i =0;i<member.size();i++)
pointer(member[i]);
return 0;
}
4.调试运行阶段:
member[2] =&c,此语句错误,提示为:worker类不明确,要将Manager向上转型为Professor或者Administrator
member[2] =dynamic_cast<Professor *>(&c)
展开全部
你可以写一个计算图形面积的程序,父类是一个点,然后三角形,矩形,立方体弊让乱滑棚继承于父类,求面积的函数实现多态,这个小问题基本把你的要求实现了,至于代码,都是很基本的租档
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询