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]> <!- ...
随机推荐
- Sass的四种编译方式
我们都知道Sass其实有两种,一种是Sass,一种是SCSS. Sass 和 SCSS 其实是同一种东西,我们平时都称之为 Sass,两者之间不同之处有以下两点: 文件扩展名不同,Sass 是以“.s ...
- Angular(2+) 国际化方案(ngx-translate)
本文只针对ngx-translate/core 6.x版本,如果你使用的是5.x或者更低的版本,请参照以下链接. https://github.com/ngx-translate/core/blob/ ...
- Oracle_建表
Oracle_建表 --设计要求: --建立一张用来存储学生信息的表 --字段包含学号.姓名.性别,年龄.入学日期.班级,email等信息 create table student( ...
- CSS学习笔记day1
1.css的简介 css:层叠样式表 (层叠:一层一层的:样式表:很多的属性和属性值) 使页面显示效果更好 将页面内容和显示样式进行分离,提高了显示功能. 2.css和html的结合方式(4种) 在 ...
- <script>的用法
<script> </script> 是指 在 HTML 页面中插入一段 JavaScript
- maven pom.xml 详细
一.什么是POM Project Object Model,项目对象模型.通过xml格式保存的pom.xml文件.作用类似ant的build.xml文件,功能更强大.该文件用于管理:源代码.配置文件. ...
- Servlet--HttpServletRequest接口,HttpServletResponse接口
HttpServletRequest接口 定义 public interface HttpServletRequest extends ServletRequest; 用来处理一个对 Servlet ...
- 在Tomcat中配置连接池和数据源
1.DataSource接口介绍 (1)DataSource 概述 JDBC1.0原来是用DriverManager类来产生一个对数据源的连接.JDBC2.0用一种替代的方法,使用DataSource ...
- HTML学习——表单标签
1.type: 当 type="radio" 时,控件为单选框 当 type="checkbox" 时,控件为复选框 2.value:提交数据到服务器的值(后台 ...
- TCP连接之未连接队列的理解[转]
tcp服务器在TCP/IP协议中,TCP协议提供可靠的连接服务,采用三次握手建立一个连接. 第一次握手:建立连接时,客户端发送syn包(syn=j)到服务器,并进入SYN_SEND状态,等待服务器确认 ...