c++项目范例
#include<iostream>
#include<string.h>
#include<stdlib.h>
using namespace std;
class Card
{
protected:
float remain;
public:
Card(){}
Card(float _remain):remain(_remain){}
float Getremain(){return remain;}
float credit(float _price);
float recharge(float moneny);
virtual void showmoney()=;
virtual void isme(float a)=;
virtual void showinfo()=;
virtual const char* Getname()=;
//virtual bool operator >(Card *c) = 0;
}; class Stu : public Card
{
protected:
int stunum;
const char *name;
public:
Stu(){}
Stu(int num,const char* _name):stunum(num),name(_name){}
Stu(float _remain,int num,const char *_name):Card(_remain),stunum(num),name(_name){}
void showmoney();
void isme(float a);
void showinfo();
const char *Getname() {return name;}
bool operator >(Card *c);
};
bool Stu::operator >(Card *c)
{
if(remain>c->Getremain())
return true;
else
return
false;
}
void Stu::showmoney()
{}
void Stu::isme(float a)
{
remain=remain - a; }
void Stu::showinfo()
{
cout<<name<<"\t"<<stunum<<"\t"<<remain<<"\t"<<endl;
} class Gra:public Stu
{
private:
float wage; public:
Gra(float _remain,int num,const char *_name,float _wage):Stu(_remain,num,_name),wage(_wage){ }
void showmoney();
void isme(float a);
void showinfo();
const char *Getname(){return name;}
bool operator >(Card *c);
};
bool Gra::operator >(Card *c)
{
if(remain>c->Getremain())
return true;
else
return
false;
}
void Gra::showmoney()
{}
void Gra::isme(float a)
{
remain = remain-a; }
void Gra::showinfo()
{
cout<<name<<"\t"<<stunum<<"\t"<<remain<<"\t"<<wage<<"\t"<<endl;
}
class Employees :public Card
{
private:
int wonum;
const char* ename;
public:
Employees( float _remain,int _wonum,const char* _ename):Card(_remain),wonum(_wonum),ename(_ename){}
void showmoney();
void isme(float a);
void showinfo();
const char *Getname(){return ename;}
bool operator >(Card *c);
};
bool Employees::operator >(Card *c)
{
if(remain>c->Getremain())
return true;
else
return
false;
}
void Employees::showmoney()
{}
void Employees::isme(float a)
{
remain = remain-a; }
void Employees::showinfo()
{
cout<<ename<<"\t"<<wonum<<"\t"<<remain<<"\t"<<endl;
} class Canteen
{
private:
const char* menu;
float price;
public:
Canteen(const char* _menu,float _price):menu(_menu),price(_price){}
void showmenu();
const char *Getmenu(){return menu;}
float getprice(){return price;}
};
void Canteen::showmenu()
{
cout<<menu<<"\t"<<price<<"\t"<<endl;
}
int main()
{
float tmp = ;
float tmp1 = ;
int i,flag1,flag2,flag3;
char pname[];
char foodbuf[];
Canteen c1("fish",10.0);
Canteen c2("leek",8.5);
Canteen c3("celery",7.2);
Canteen c4("cole",5.8);
Canteen c5("buds",6.9);
Canteen *p1[]={&c1,&c2,&c3,&c4,&c5};
Stu s(150.0,,"timi");
Stu s1(200.0,,"tom");
Gra g(180.0,,"lucy",700.0);
Gra g1(200.0,,"jay",700.0);
Employees e(190.0,,"jimi");
Card *p[] = {&s,&s1,&g,&g1,&e};
cout<<"people infomation:\n"<<endl;
cout<<"NO.\t"<<"name\t"<<"num\t"<<"remain\t"<<"wage\t"<<endl;
for(i=;i<;i++)
{
cout<<i<<"\t";
p[i]->showinfo();
} cout<<"input name who is you:"<<endl;
char *cp;
cin>>pname; cout<<endl; for(i=;i<;i++)
{
if(!strncmp(pname,p[i]->Getname(),strlen(pname)-))
{
cout<<"NO.\t"<<"name\t"<<"num\t"<<"remain\t"<<"wage\t"<<endl;
cout<<i<<"\t";
p[i]->showinfo();
flag1 = i;
break;
} } while()
{
cout<<"1: list\t\t2: take your order\t3:show max and min\t0:quit\t"<<endl;
cout<<"please input your select:"<<endl;
int select;
cin>>select;
switch(select)
{
case : exit();
case :{
cout<<"NO.\t"<<"food\t"<<"price\t"<<endl;
for(i=;i<;i++)
{
cout<<i<<"\t";
p1[i]->showmenu(); }
break;
}
case :{
cout<<"NO.\t"<<"food\t"<<"price\t"<<endl;
for(i=;i<;i++)
{
//cout<<i<<"\t";
p1[i]->showmenu(); }
cout<<"please input which do you like:"<<endl;
cin>>foodbuf;
for(i=;i<;i++)
{//cout<<"hello"<<endl;
if(!strncmp(foodbuf,p1[i]->Getmenu(),strlen(foodbuf)-))
{ //cout<<"hello"<<endl;
p[flag1]->isme(p1[i]->getprice());
cout<<"remaining:"<<p[flag1]->Getremain()<<endl;
} }
for(i=;i<;i++)
{ //cout<<"hello\n";
if(tmp < p[i]->Getremain())
{
tmp = p[i]->Getremain();
flag2 = i;
}
} for(i=;i<;i++)
{
if(tmp1>p[i]->Getremain())
{tmp1 = p[i]->Getremain();
flag3 = i;}
} cout<<"the max is:"<<endl;
p[flag2]->showinfo();
cout<<"the min is:"<<endl;
p[flag3]->showinfo();
break;
}
case :
{
Card *maxp = p[],*minp = p[];
for(i=;i<;i++)
{
if(p[i]>p[i+])
{
minp = p[i-];
cout<<i<<endl;
}
}
for(i=;i<;i++)
{
if(p[i+]>p[i])
{
maxp = p[i];
cout<<i-<<endl;
}
}
cout<<"the min remain is:"<<endl;
minp->showinfo();
cout<<"the max remain is:"<<endl;
maxp->showinfo(); break;
} default:{break;}
}
}
}
c++项目范例的更多相关文章
- [2017BUAA软工助教]个人项目小结
2017BUAA个人项目小结 一.作业链接 http://www.cnblogs.com/jiel/p/7545780.html 二.评分细则 0.注意事项 按时间完成并提交--正常评分 晚交一周以内 ...
- HTML的页面IE注释
我们常常会在网页的HTML里面看到形如[if lte IE 9]……[endif]的代码,表示的是限定某些浏览器版本才能执行的语句,那么这些判断语句的规则是什么呢?请看下文: <!--[if ! ...
- 判断IE版本的HTML语句详解,如:[if lte IE 9]……[endif]
我们常常会在网页的HTML里面看到形如[if lte IE 9]……[endif]的代码,表示的是限定某些浏览器版本才能执行的语句,那么这些判断语句的规则是什么呢?请看下文: <!--[if ! ...
- 条件注释判断浏览器版本<!--[if lt IE 9]>
<!--[if !IE]><!--> 除IE外都可识别 <!--<![endif]--><!--[if IE]> 所有的IE可识别 <![e ...
- 条件注释判断浏览器<!--[if !IE]><!--[if IE]><!--[if lt IE 6]><!--[if gte IE 6]>
<!--[if !IE]><!--> 除IE外都可识别 <!--<![endif]--><!--[if IE]> 所有的IE可识别 <![e ...
- IE条件注释
<!--[if !IE]><!--> 除IE外都可识别 <!--<![endif]--> <!--[if IE]> 所有的IE可识别 <![ ...
- 通过HTML条件注释判断IE版本的HTML语句详解<!--[if IE]> <![endif]-->
我们常常会在网页的HTML里面看到形如[if lte IE 9]……[endif]的代码,表示的是限定某些浏览器版本才能执行的语句,那么这些判断语句的规则是什么呢?请看下文: <!--[if ! ...
- Bootstrap+MetroNic_1.5.4 Head meta
Bootstrap+MetroNic_1.5.4 HTML <meta> 标签设定含义: <meta http-equiv="X-UA-Compatible" c ...
- 浏览器兼容性判定写法格式(ie)
条件注释判断浏览器<!--[if !IE]><!--[if IE]><!--[if lt IE 6]><!--[if gte IE 6]> <!- ...
随机推荐
- iptables命令 高级网络
http://man.linuxde.net/iptables iptables命令是Linux上常用的防火墙软件,是netfilter项目的一部分.可以直接配置,也可以通过许多前端和图形界面配置. ...
- Java读书推荐
想要深入掌握一门技术,读书是必不可少的一步,也是最重要的一步.有些书需要读很多遍才能深入理解,经过几本甚至几十本书的熏陶,才能让你在这个行业中越走越远,爱上这个行业,抽出时间多读本书吧,读书会让人如虎 ...
- Linuxc - 执行c程序
1.新建工作空间 root@jiqing-virtual-machine:~/cspace/les1# pwd /root/cspace/les1 2.新建c程序 root@jiqing-virtua ...
- CentOS7中使用iptables
原文地址:http://blog.csdn.net/u012486840/article/details/53161555 1.关闭firewall: systemctl stop firewalld ...
- linux_网站计量单位
IP 独立IP数,是不同IP地址的计算机访问网站时被计算的总次数,独立IP数是衡量网站流量的一个重要指标,一般一天内相同IP地址的客户端访问网页只被计算为一次,记录独立IP的时间为一天或一个月,目前通 ...
- Linux磁盘热插拔命令
对于支持热插拔SCSI技术的服务器,SCSI硬盘和磁带机可以在Linux下实现在线添加和移除,有两种方法实现,先说麻烦的 具体方法如下: 一. 添加或者删除硬盘/磁带机: # echo "s ...
- 输入和输出--IO流
JavaIO流 首先要理解这个"流"(stream)字:Java把不同的输入,输出源抽象成为流,通过流的方式允许Java程序使用相同的方式来访问不同的输入,输出源.把这里的&quo ...
- JAVA中JPA的主键自增长注解设置
JPA的注解来定义实体的时候,使用@Id来注解主键属性即可.如果数据库主键是自增长的,需要在增加一个注解@GeneratedValue,即: @GeneratedValue(strategy=Gene ...
- 定时任务schedule(spring boot )
1. 定时任务实现方式:SpringBoot自带的Scheduled,可以将它看成一个轻量级的Quartz,而且使用起来比Quartz简单许多,本文主要介绍. 执行方式:单线程(串行)多线程(并行) ...
- zabbix agent(Active)模式 /克隆修改模板
这个模式主要是用于server端被动接收数据,不发送探测请求 agent端主动发送数据,不接收探测请求 被监控端 zabbix_Agentd.conf 的配置调整 LogFile=/tmp/zabbi ...