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]> <!- ...
随机推荐
- slice、splice与split傻傻分不清
每每看到这几个,就蒙圈了,这都是啥呀? 既然这么容易混淆,我还是来做个小笔记吧,以便日后查阅: 1.slice(数组) 定义:slice() 方法可从已有的数组中返回选定的元素. 用法:array ...
- java中类的加载过程和对象的创建过程
1.类加载过程 首先,jvm在执行时,遇到一个新的类,会先去内存的方法区中去寻找该类的.class文件,如果找到了就直接运行,如果没有找到,则会去硬盘中去寻找该类的.class文件,并将该类文件加载到 ...
- 关于vueThink框架打包发布的一些问题
刚开始发布自己的vueThink项目的时候,总是出现404错误,后来经过上网查找,发现是路径的问题,这方面的知识,网上很多,就不过多阐述了.我主要想说的是自己的项目发布的时候,admin账号登录的时候 ...
- Asp.net mvc 中Action 方法的执行(一)
[toc] 在 Aps.net mvc 应用中对请求的处理最终都是转换为对某个 Controller 中的某个 Action 方法的调用,因此,要对一个请求进行处理,第一步,需要根据请求解析出对应的 ...
- Java 得到泛型中得到T.class
Class <T> entityClass = (Class <T>) ((ParameterizedType) getClass().getGenericSuperclass ...
- 写一个简单的配置文件和日志管理(shell)
最近在做一个Linux系统方案的设计,写了一个之前升级服务程序的配置和日志管理. 共4个文件,服务端一个UpdateServer.conf配置文件和一个UpdateServer脚本,客户端一个Upda ...
- linux 3.10的kdump配置的小坑
之前在2.6系列linux内核中,当发现某个模块不要在保留内核中加载的时候,可以通过blacklist参数将其在/etc/kdump.conf中屏蔽 blacklist <list of ker ...
- arduino与DS1302时钟调试失败的分析
前两天测试了时钟模块,但是,一直失败,能读取时间,但是设置不了时间,所以.这次我查了很多资料,发现好像是信号线的问题,线太长,数据收到干扰, 资料如下http://www.51hei.com/bbs/ ...
- 解决span的bug--不能自动换行的问题
span标签元素不能自动换行,在超出父盒子的宽度后不能够自动换行 如下界面: 解决办法:将span属性加上display:block设置为行级元素:设置宽度然后在强制断行 效果如下:
- springcloud(十二):使用Spring Cloud Sleuth和Zipkin进行分布式链路跟踪
随着业务发展,系统拆分导致系统调用链路愈发复杂一个前端请求可能最终需要调用很多次后端服务才能完成,当整个请求变慢或不可用时,我们是无法得知该请求是由某个或某些后端服务引起的,这时就需要解决如何快读定位 ...