1. 采用面向对象的方式编写一个通迅录管理程序,通迅录中的信息包括:姓名,公司,联系电话,邮编。要求的操作有:添加一个联系人,列表显示所有联系人。先给出类定义,然后给出类实现。(提示:可以设计二个类,一个通迅录条目类CommEntry,一个通讯录类Commus)

class CommEntry
{
public:
CommEntry();
~CommEntry();
virtual void input();
virtual void output();
void setName(string nm);
void setTel(string t);
string getName();
string getTel();
void setTelCount(int c);
private:
string name;
int telCount;
string tel;
string telType;
}; class FreindEntry: public CommEntry
{
public:
void input();
void output();
void setEmail(string nm);
string getEmail();
private:
string Email;
}; class Comms
{
public:
Comms(int max=);
~Comms();
void inputAll();
void outputAll();
void find(string nm);
void modify_tel(string nm);
private:
CommEntry **pCe;
int maxCount;
int count;
};
Comms::Comms(int maxCount)
{
pCe = new CommEntry * [maxCount];
}
Comms::~Comms()
{
int i;
for(i=; i<=count; i++)
{
delete pCe[i];
}
delete []pCe;
}
 if (iC==)
{
pCe[i]= new CommEntry;
}
else if(iC==)
{
pCe[i]= new FreindEntry;
}
pCe[i]->input();

/*Employee 和Manager,Manager 是一种特殊的Employee。
Employee 对象所具有的基本信息为:姓名、年令、工作年限、部门号,
对象除具有上述基本信息外,还有级别(level)信息。公司中的两类职

输出Employee/Manager 对象的个人信息
retire() // 判断是否到了退休年令,是,屏幕给出退休提示。公司规定:
类对象的退休年令为55 岁,Manager 类对象的退休年令为60 岁

定义并实现类Employee 和Manager;
(注意:Manager继承自Employee)
定义一个测试程序,测试所定义的类Employee 和Manager*/

#include<iostream>
#include<string>
using namespace std;
class Employee
{
public:
Employee();
Employee(string the_name,int the_age,int the_wokeage,string the_depNo);
void printOn();
void retire();
protected:
string name;
int age;
int wokeage;
int number;
string depNo;//部门号
}; class Manager:public Employee
{
public:
Manager();
Manager(string the_name,int the_age,int the_wokeage,string the_depNo,int the_level);
void printOn();
void retire();
void addMember(Employee*);
private:
int level;
Employee numOfEmployee[];
};
Employee::Employee():name("no name yet!"),age(),wokeage(),depNo("no name yet!")
{
}//初始化列表 Employee::Employee(string the_name,int the_age,int the_wokeage,string the_depNo)
{
name=the_name;
age=the_age;
wokeage=the_wokeage;
depNo=the_depNo;
}
void Employee::printOn()
{
cout<<"name is "<<name<<endl
<<"age is "<<age<<endl
<<"wokeage is "<<wokeage<<endl
<<"bumen number is "<<number<<endl;
} void Employee::retire()
{
if(age>=)
cout<<"retire!\n";
else
cout<<"not retire!\n";
} Manager::Manager():level()
{
}
Manager::Manager(string the_name,int the_age,int the_wokeage,string the_depNo,int the_level)
:Employee(the_name,the_age,the_wokeage,the_depNo),level(the_level)
{ }//初始化列表
void Manager::printOn()
{
cout<<"name is "<<name<<endl
<<"age is "<<age<<endl
<<"wokeage is "<<wokeage<<endl
<<"bumen number is "<<number<<endl
<<"level is "<<level<<endl;
}
void Manager::retire()
{
if(age>=)
cout<<"retire!\n";
else
cout<<"not retire!\n";
} void Manager::addMember(Employee* e)
{
numOfEmployee[]=*e;
}
int main()
{
Employee e("Jack", , , "Development");
Manager m("Tom", , , "Development", );
m.addMember(&e);//m管理e
e.printOn();
m.printOn();
Employee* p = &e;//基类指针指向基类对象
p->retire(); // 如果雇员的年龄是55,则b为true
p = &m;//基类指针指向派生类对象
p->retire (); // 如果管理者的年龄是60,则 b为true
return ;
}

3. 已知类的定义如下:

class Base {

protected:

int iBody;

public:

virtual void printOn() = 0;

Base(int i = 0) : iBody(i) {}

virtual int display(int x=60) {iBody = x;return iBody;}

};

class Sub1 : public Base {

// …

public:

// …

Sub1(int i, string s);

};

class Sub2 : public Base {

// …

public:

// …

Sub2(int i, short s);

};

试完成类Sub1和Sub2的定义和操作的实现代码,使之能符合下面程序及在注释中描述的运行结果的要求:

main(){

Sub1 s1(1000, "This is an object of Sub1");

Sub2 s2(1000, 20);

s1.printOn();         // 此时显示出: 1000: This is an object of Sub1

s2.printOn();         // 此时显示出: 20 and 1000

cout<<s2.display(20); // 此时显示出: 20

}

#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
class Base
{
protected:
int iBody;
public:
virtual void printOn() = ;
Base(int i = ) : iBody(i) {}//构造函数,初始化列表
virtual int display(int x=)
{
iBody = x;
return iBody;
}
};
class Sub1 : public Base
{
string cpString;
public: Sub1(int i, string s) : Base(i),cpString(s)
{ }
void printOn()
{
cout<<iBody<<":"<<cpString<<endl;
}
};
class Sub2 : public Base
{
short sShort;
public: Sub2(int i, short s) : Base(i),sShort(s) {}
void printOn()
{
cout<<sShort<<" and "<<iBody<<endl;
}
int display(int x=)
{
sShort = x;
return sShort;
}
}; int main()
{
Sub1 s1(, "This is an object of Sub1");
Sub2 s2(, );
s1.printOn(); // 此时显示出: 1000: This is an object of Sub1
s2.printOn(); // 此时显示出: 20 and 1000
cout<<s2.display(); // 此时显示出: 20
return ;
}

4. 在一个GUI程序中,有一系列相关的类,如circle,triangle,square等等,其中square由二个triangle对象构成. circle,triangle,square等类的对象都有相似的行为print(string)(打印出该类对象的相应信息,如类circler的此函数输出”Circle”),draw()(画出相应的类对象的图形),我们应如何组织这些类,使得系统易于扩充和维护?请用UML语言画出类图,并给出相应类中方法的界面(头文件).

补充一道期末考试题。

5.

#include <iostream>
using namespace std;
void hello( ) { cout << " Hello, world!\n"; }
int main( ) {
hello( ); return ;
}

试修改上面的程序,使其输出变成:
 Begin
   Hello, world!
 End
限制:(1)不能对main()进行任何修改;(2)不能修改hello()函数。

解题思路:利用类的构造函数和析构函数来实现!!!

#include <iostream>
using namespace std;
class A {
public:
A ( ) { cout << "Begin\n"; }
~A ( ) { cout << "End\n"; }
}; void hello( ) {cout << " Hello, world!\n"; } A a; // a是一个全局对象
int main( ) {
hello( );
return ;
}

C++设计考试例题的更多相关文章

  1. 基于Web在线考试系统的设计与实现

    这是一个课程设计的文档,源码及文档数据库我都修改过了,貌似这里复制过来的时候图片不能贴出,下载地址:http://download.csdn.net/detail/sdksdk0/9361973   ...

  2. C#基础视频教程6.3 如何简单读写数据库

    在继续往下做之前,我们需要把之前的代码尽可能的精简(会对后面很有好处,而且读者也应该仔细比对这一部分的代码和上一部分哪里真正得到了优化,从而提高编程水平). 首先数据库的操作类有哪些是可以做的更加普遍 ...

  3. 2017.10.26 JavaWeb----第五章 JavaBean技术

    JavaWeb----第五章 JavaBean技术 (1)JavaBean技术 JavaBean技术是javaweb程序的重要组成部分,是一个可重复使用的软件组件,是用Java语言编写的.遵循一定的标 ...

  4. 关于托福改革后的难度、评分和拼分,听听ETS的老师怎么说

    “笔者有幸于几天前去到ETS位于普林斯顿的总部学习,聆听了他们关于托福考试的发展和变革的说明,在这里向大家汇报一下此行的收获.” 当从车上下来那一刻起,我们便被那辽阔的绿草地和宜人的风景所吸引,伴随着 ...

  5. 《Spring_Four》第三次作业——基于Jsoup的大学生考试信息展示系统的原型设计与开发

    <Spring_Four团队>第三次团队项目——基于Jsoup的大学生考试信息展示系统的原型设计与开发 一.实验目的与要求 (1)掌握软件原型开发技术: (2)学习使用软件原型开发工具:本 ...

  6. 课程设计之"网络考试系统"(php、Extjs)

    1.TestSystem大概结构框图 2.数据库设计(11张表) 数据库名称:db_testsystem 数据库表: tb_admin 记录题库管理员帐户信息 代码 tb_allcontent 记录随 ...

  7. MongoDB实现问卷/考试设计

    MongoDB的特点 MongoDB是一个面向文档存储的数据库.在MongoDB中,一条记录叫做document(文档),由类似于JSON结构的键值对组成. 由于类似于MongoDB直接存储JSON的 ...

  8. 基于B/S架构的在线考试系统的设计与实现

    前言 这个是我的Web课程设计,用到的主要是JSP技术并使用了大量JSTL标签,所有代码已经上传到了我的Github仓库里,地址:https://github.com/quanbisen/online ...

  9. 紫书 例题 9-3 UVa 1347 ( 状态设计)

    首先做一个转化,这种转化很常见. 题目里面讲要来回走一遍,所以就转化成两个从起点到终点,路径不重合 那么很容易想到用f[i][j]表示第一个走到i,第二个人走到j还需要走的距离 但是这里无法保证路径不 ...

随机推荐

  1. Vmare 无法打开内核设备“\\.\VMCIDev\VMX”: 系统找不到指定的文件。您在安装 VMware Workstation 后是否进行了重新引导?的解决办法

    1.使用管理员省份运行cmd:net start vmx86(切记是要用管理员身份),启动服务成功问题即可解决. 2.若1操作中启动失败,则到Vmare安装目录下搜索vmx86.sys文件,并拷贝到C ...

  2. 《Java练习题》习题集五

    编程合集: https://www.cnblogs.com/jssj/p/12002760.html Java总结:https://www.cnblogs.com/jssj/p/11146205.ht ...

  3. 《Java练习题》习题集四

    编程合集: https://www.cnblogs.com/jssj/p/12002760.html Java总结:https://www.cnblogs.com/jssj/p/11146205.ht ...

  4. 线上服务器CPU彪高的调试方式

    原文内容来自于LZ(楼主)的印象笔记,如出现排版异常或图片丢失等问题,可查看当前链接:https://app.yinxiang.com/shard/s17/nl/19391737/2fee7b91-f ...

  5. CreateDefaultBuilder方法都做了什么?

    当我们创建好一个新的ASP.NET Core Web应用时,系统会使用CreateDefaultBuilder方法,这个方法完成了以下操作: use Kestrel as the web server ...

  6. ubuntu14.04编译vim8.1

    安装依赖 这一步其实我没做,直接下载编译成功了.估计有些包不是必需的.姑且列在这里供参考 sudo apt install libncurses5-dev libgnome2-dev libgnome ...

  7. 用故事说透 HTTPS

    本文来自素燕公众号,原文地址:用故事说透 HTTPS 故事中的主演:小华今年上大一,这是她第一次离开父母,独自一人到北京上学.今天妈妈的生日,想了想要给妈妈一个祝福,便给妈妈发了条消息:妈妈收到这条消 ...

  8. VUE项目Eslint报错

    前言:eslint很恶心的一个地方:你是否被各种语法报错一个标点符号,一个空格,一个回车......各种报错折磨着你! 加上编辑器 VS Code 的自动格式化稳稳的和Eslint冲突报错. 对此,我 ...

  9. DG中switchover切换操作

    问题描述:我们配置DG的目的就是为了在主库出现故障时,备库能够提供服务,保证业务的正常运行,switchover是用户有计划的进行停机切换,能够保证不丢失数据,我记录一下我进行switchover中的 ...

  10. docker安装redis 5.0.7并挂载外部配置和数据

    环境 CentOS Linux release 7.7.1908 (Core) 拉取redis 5.0.7 镜像 docker pull redis:5.0.7 创建挂载目录 mkdir -p /ho ...