南阳康佳管理系统
来源:互联网 发布:js如何让点击事件失效 编辑:程序博客网 时间:2024/04/28 15:47
设计南阳康佳公司的设备管理系统
一、 课程设计题目:完成南阳康佳公司的设备管理系统
二、 目的与要求:
1、目的:
(1)要求学生达到熟练掌握C++语言的基本知识和技能;
(2)基本掌握面向对象程序设计的基本思路和方法;
(3)能够利用所学的基本知识和技能,解决简单的面向对象程序设计问题。
2、基本要求:
(1)要求利用面向对象的方法以及C++的编程思想来完成系统的设计;
(2)要求在设计的过程中,建立清晰的类层次;
(3)在系统中至少要定义四个类,每个类中要有各自的属性和方法;
(4)在系统的设计中,至少要用到面向对象的一种机制。
3、创新要求:
在基本要求达到后,可进行创新设计,如根据查找结果进行修改的功能。
4、写出设计说明书
三、设计方法和基本原理:
1、问题描述(功能要求):
南阳康佳公司现有以下设备:普通电视机、DVD、带DVD的电视机,带DVD的电视机的售价为普通电视机和DVD单价之和的80%,要求对所有的库存设备都能按照品名进行显示、查找、增加和删除、保存的功能。
2、问题的解决方案:
根据系统功能要求,可以将问题解决分为以下步骤:
(1)分析系统中的各个实体之间的关系及其属性和行为;
(2)根据问题描述,设计系统的类层次;
(3)完成类层次中各个类的描述(包括属性和方法);
(4)完成类中各个成员函数的定义;
(5)完成系统的应用模块;
(6)功能调试;
(7)完成系统总结报告以及系统使用说明书。
四、报告:
包括系统设计要求,设计思路,系统功能模块图,系统流程图,类的层次图(包括类成员列表),调试过程,关键程序代码,总结,参考书目等。
代码:
#include<iostream> #include<fstream> #include<string> #include<iomanip> using namespace std; class machine //定义machine为基类 { protected: char name[20]; float price; int machineno; static int n; public: machine(); ~machine(){} void setname(char *names); char *getname(); void setprice(float pr); float getprice(); int getnum(); }; //以下都为machine的派生类 class TV: virtual public machine //TV和DVD都定义虚基类公有继承 { public: TV() {} }; class DVD: virtual public machine { public: DVD(){} }; class DVD_TV: public TV, public DVD { public: DVD_TV(){} float getprice(float p1,float p2); }; int machine::n=0; //初始化机器编号 machine::machine() //每增加一台机器编号自动加一 {machineno=n++;} void machine::setname(char*names) //用来设置机器的品名 {strcpy(name,names);} char *machine::getname() //用来获取机器的品名 {return name;} void machine::setprice(float pr) //初始化机器价钱 {price=pr;} float machine::getprice() //获得机器价钱 {return price;} int machine::getnum() //获取机器编号 {return machineno;} float DVD_TV::getprice(float p1,float p2) //计算DVD_TV的方法 {return (p1+p2)*0.8;} //文件异常处理 class fileexception { public: fileexception() :message("file is not created!") {} const char *what() const{return message;} private: const char *message; }; machine *j1; //定义一个基类指针对象 TV T1; DVD D1; DVD_TV DT1; //以下为函数声明 void add(); void output(); void search(); void deleteinf(); void save(); void main() { cout<<setw(60)<<" **************欢迎进入南阳康佳公司设备管理系统**************"<<endl; do { cout<<setw(60)<<" ************************************************************"<<endl; cout<<setw(60)<<" ***** *****"<<endl; cout<<setw(60)<<" ***** 1.添加相关信息 2.输出相关信息 *****"<<endl; cout<<setw(60)<<" ***** 3.查询相关信息 4.删除相关信息 *****"<<endl; cout<<setw(60)<<" ***** 5.保存相关信息 0.退出 *****"<<endl; cout<<setw(60)<<" ***** *****"<<endl; cout<<setw(60)<<" ************************************************************"<<endl; int choose; cin>>choose; switch(choose) { case 0: cout<<"欢迎再次使用该系统!"<<endl; exit(0); break; case 1: add(); break; case 2: output(); break; case 3: search(); break; case 4: deleteinf(); break; case 5: save(); break; default: cout<<"输入无效!请重新输入!"<<endl; break; } }while(!0); } void add() { char names[20]; int kind,choose; cout<<"请输入machine的类型(1·普通电视机 2·DVD 3·带DVD的电视机):" ; cin>>kind; while(kind<1 ||kind>3) { cout<<"输入错误!请重新选择:"; cin>>kind; } cout<<"请输入品名:"; cin>>names; switch(kind) { case 1: j1=&T1;break; case 2: j1=&D1;break; case 3: j1=&DT1;break; } if(kind==1||kind==2) { j1->setname(names); float price; cout<<"价格为:"; cin>>price; j1->setprice(price); cout<<"该产品的相关信息为:"<<endl; cout<<"编号为:"<<j1->getnum()<<" 该产品名称为:"<<j1->getname()<<" 价格为:"<<j1->getprice()<<endl; } else { j1->setname(names); DT1.setname(names); cout<<"该类型为:"<<DT1.getname(); float price1,price2,price3; cout<<"请输入上述普通电视机的价格:"; cin>>price1; cout<<"请输入上述DVD的价格:"; cin>>price2; price3=(price1+price2)*8/10; DT1.setprice(price3); cout<<"该产品的相关信息为:"<<endl; cout<<"编号为:"<<j1->getnum()<<" 该产品名称为:"<<DT1.getname()<<" 价格为:"<<DT1.getprice(price1,price2)<<endl; } cout<<"是否将该产品信息存入文件:(1、是 2、否):"; cin>>choose; while(choose!=1 &&choose!=2) { cout<<"输入错误!请重新选择:"; cin>>choose; } if(choose==1) save(); } void output() { ifstream infile("南阳设备管理系统.txt",ios::in); try{ if(!infile) throw fileexception(); } //捕获由throw表达式抛掷的异常 catch(fileexception fe) { cout<<fe.what()<<endl; exit(0); } cout<<"从文件中读取的数据如下:"<<endl; char line[101]; for(int i=0;i<3;i++) { infile.getline(line,100); cout<<line<<endl; } infile.close(); } void search() { char line[100]; int i=1,n; cout<<"请输入要查询的序号:"; cin>>n; ifstream infile("南阳设备管理系统.txt",ios::in); try{ if(!infile) throw fileexception(); } catch(fileexception fe) { cout<<fe.what()<<endl; exit(0); } while(!infile.eof()) { infile.getline(line,100); if(i==n) { cout<<line<<endl; break; } i++; if(infile.eof()) cout<<"没找到相应的产品!"<<endl; } } void deleteinf() { ifstream ifile("南阳设备管理系统.txt"); ofstream ofile("temp.txt"); char line[100]; int i=1,n; cout<<"请输入要查询的序号:"; cin>>n; while(!ifile.eof()) { ifile.getline(line,100); //读取完之后,从读取的内容中删除该终止字符 if(i!=n) { ofile<<line<<endl; } i++; } ifile.close(); ofile.close(); system("del 南阳设备管理系统.txt"); system("rename temp.txt,南阳设备管理系统.txt"); cout<<"该产品已成功删除!"<<endl; cout<<"查看是否已被删除?(0-否、1-是):"; int number; cin>>number; if(number) output(); } void save() { ofstream ofile("南阳设备管理系统.txt",ios_base::app); //抛出错误 try{ if(!ofile) throw fileexception(); } catch(fileexception fe) { cout<<fe.what()<<endl; exit(0); } //写入文件 ofile<<"编号为:"<<j1->getnum()<<" 该产品名称为:"<<j1->getname()<<" 价格为:"<<j1->getprice()<<endl; ofile.close(); cout<<"该厂品信息已存入文件!"<<endl; }
- 南阳康佳管理系统
- C++课程设计( 南阳康佳公司的设备管理系统 )
- 南阳宾馆管理系统
- 南阳理工学院软件学院毕业设计跟踪管理系统介绍
- 南阳
- 7.25南阳理工acm评测系统数据结构
- 康佳试水无线K-Java技术
- 智能拼图和魔法寿司-康佳6670
- 康佳W810 root教程_方法
- 南阳理工学院在线评测系统-兄弟郊游问题
- 管理系统
- 管理系统
- 管理系统
- 管理系统
- 从康佳电视屏幕碎了看康佳与大中电器
- 商品管理录入管理系统
- 数据库管理系统的管理
- 创维黄宏生、TCL李东生及康佳陈伟荣悲喜人生
- 路灯
- 获取静态文本的内容
- 不包含某字符串的字符串匹配 (正则表达式)
- 答辩
- 12.12扫雷编码
- 南阳康佳管理系统
- CreateThread与AfxBeginThread区别
- Java EE 6 和 GlassFish v3发布了
- 希赛网的面向对象专题链接
- 博客第一篇
- [转]硬盘 结构 原理 磁道,扇区和柱面图示
- JSP连接Sql Server2000
- WIN32多线程程序设计学习笔记[转]
- ubuntu9.10 texlive 2009 简单安装教程