#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++项目范例的更多相关文章

  1. [2017BUAA软工助教]个人项目小结

    2017BUAA个人项目小结 一.作业链接 http://www.cnblogs.com/jiel/p/7545780.html 二.评分细则 0.注意事项 按时间完成并提交--正常评分 晚交一周以内 ...

  2. HTML的页面IE注释

    我们常常会在网页的HTML里面看到形如[if lte IE 9]……[endif]的代码,表示的是限定某些浏览器版本才能执行的语句,那么这些判断语句的规则是什么呢?请看下文: <!--[if ! ...

  3. 判断IE版本的HTML语句详解,如:[if lte IE 9]……[endif]

    我们常常会在网页的HTML里面看到形如[if lte IE 9]……[endif]的代码,表示的是限定某些浏览器版本才能执行的语句,那么这些判断语句的规则是什么呢?请看下文: <!--[if ! ...

  4. 条件注释判断浏览器版本<!--[if lt IE 9]>

    <!--[if !IE]><!--> 除IE外都可识别 <!--<![endif]--><!--[if IE]> 所有的IE可识别 <![e ...

  5. 条件注释判断浏览器<!--[if !IE]><!--[if IE]><!--[if lt IE 6]><!--[if gte IE 6]>

    <!--[if !IE]><!--> 除IE外都可识别 <!--<![endif]--><!--[if IE]> 所有的IE可识别 <![e ...

  6. IE条件注释

    <!--[if !IE]><!--> 除IE外都可识别 <!--<![endif]--> <!--[if IE]> 所有的IE可识别 <![ ...

  7. 通过HTML条件注释判断IE版本的HTML语句详解<!--[if IE]> <![endif]-->

    我们常常会在网页的HTML里面看到形如[if lte IE 9]……[endif]的代码,表示的是限定某些浏览器版本才能执行的语句,那么这些判断语句的规则是什么呢?请看下文: <!--[if ! ...

  8. Bootstrap+MetroNic_1.5.4 Head meta

    Bootstrap+MetroNic_1.5.4 HTML <meta> 标签设定含义: <meta http-equiv="X-UA-Compatible" c ...

  9. 浏览器兼容性判定写法格式(ie)

    条件注释判断浏览器<!--[if !IE]><!--[if IE]><!--[if lt IE 6]><!--[if gte IE 6]> <!- ...

随机推荐

  1. Java排序算法分析与实现:快排、冒泡排序、选择排序、插入排序、归并排序(二)

    一.概述: 上篇博客介绍了常见简单算法:冒泡排序.选择排序和插入排序.本文介绍高级排序算法:快速排序和归并排序.在开始介绍算法之前,首先介绍高级算法所需要的基础知识:划分.递归,并顺带介绍二分查找算法 ...

  2. include指令与include动作的区别(面试要考)

    include指令: 语法格式:<%@ include file=" " ...%> 发生作用的时间:页面转换期间 包含的内容:页面的实际内容 转换成的servlet: ...

  3. jquery ajax 请求中多出现一次OPTIONS请求及其解决办法

    http://www.tangshuang.net/2271.html 在上一篇<服务端php解决jquery ajax跨域请求restful api问题及实践>中,我简单介绍了如何通过服 ...

  4. Phpstorm10 主题下载

    ================================================================================ submit:主题 http://ww ...

  5. dedecms====phpcms 区别==[工作]

    {template "content","header"}{dede:include filename="head.htm"/} ----- ...

  6. 【翻译】A Next-Generation Smart Contract and Decentralized Application Platform

    原文链接:https://github.com/ethereum/wiki/wiki/White-Paper 当中本聪在2009年1月启动比特币区块链时,他同时向世界引入了两种未经测试的革命性的新概念 ...

  7. 【编程技巧】java不使用第三个变量处理两个变量的交换

    public class SwapNum {public static void main(String[] args) {doSwapNum();}public static void doSwap ...

  8. HTML <select>标签

    1.简单的下拉列表 <html> <body> <form> 名: <select name="firstname"> <op ...

  9. designed principle

    Review Of designed Pattern principle OutLine: Explanation in principles of designed pattern and usef ...

  10. JVM-类的四种载入方式

    package org.burning.sport.javase.classloader; public class ClassLoaderMain { public static void main ...