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]> <!- ...
随机推荐
- 【学习笔记】js下拉刷新、上拉加载 mescroll框架的使用
写在前边: 工作需要,使用ajax在原来的列表下边使用ajax请求后台数据,拼接在列表最下边,在github转了好久,发现了一个bug极多的js刷新插件,尝试了一个下午,就在快放弃的时候,发现下边有留 ...
- phpmyadmin 自动登录的办法
在本地开发php项目中,需要配合使用mysql在线管理系统phpmyadmin,因为经常使用,就不想每次都输入密码,所以想办法把用户名密码写入配置文件中,让每次都可以自动登录. 工具/原料 代码编 ...
- 在Vue项目使用quill-editor带样式编辑器(更改插入图片和视频)
vue-quill-editor默认插入图片是直接将图片转为base64再放入内容中,如果图片比较大的话,富文本的内容就会很大. 插入视频是直接弹框输入URL地址,某些需求下我们需要让用户去本地选择自 ...
- FileZilla出现Failed to convert command to 8 bit charset
FileZilla这款FTP客户端软件,自从华哥使用以来,采用其默认的设置,一直用得很顺畅,没有出现过什么问题.但是今天碰到了一个问题.如图. 错误信息为:Failed to convert comm ...
- 为什么要进行URL编码
我们都知道Http协议中参数的传输是"key=value"这种简直对形式的,如果要传多个参数就需要用“&”符号对键值对进行分割.如"?name1=value1&a ...
- IOS学习笔记27—使用GDataXML解析XML文档
http://blog.csdn.net/ryantang03/article/details/7868246
- Java中泛型数组创建总结
在java中,可以声明一个泛型数组,不能通过直接通过T[] tarr=new T[10]的方式来创建数组,最简单的方式便是通过Array.newInstance(Classtype,int size) ...
- python 程序退出方式
sys.exit() 执行该语句会直接退出程序,这也是经常使用的方法,也不需要考虑平台等因素的影响,一般是退出Python程序的首选方法. 该方法中包含一个参数status,默认为0,表示正常退出,也 ...
- 针对php脚本文件执行锁定的代码,避免脚本在同一时间重复运行
<?php//针对php脚本文件执行锁定的代码,避免脚本在同一时间重复运行,http://ken.01h.net/define('PHP_LOCK_FILE', dirname(__FILE__ ...
- Linux cp 移动的时候报错
报错如下: cp: omitting directory `./nginx-1.12.1' 原因: 要移动的目录下还存在有目录 解决: cp -r 文件名 地址 注意: 这里的-r代表递归 ...