电梯面向对象课程设计
1. 中国人民大学网络教育学院 《面向对象程序设计》结课设计
面向对象程序设计内容为三部分:可运行exe文件,源代码,开发文档。
主要采用C+语言编写,基础功能必须实现,其它部分功能为加分项,可根据个人能力自行选择。
运行文件:在制定环境下运行,并实现数据保存,修改,重命名等功能。
源代码:运行文件的代码组成部分。
开发文档:程序运行环境,开发过程,及程序可实现功能详解,最后课程建议等。
注意:1、编写时数据库的连接2、提交文件为压缩文件3、文件小于10M。
2. 面向对象方法课程设计(个人通讯录)
个人通讯录de
面向对象方法设计.
3. 《面向对象程序设计》课程设计
#include<iostream.h>
#include<string.h>
#include<fstream.h>
class stu
{
char name[20];
double math,chinese,english,average,sum;
public:
stu()
{
}
stu(char n[20],double ma,double chin,double eng)
{
strcpy(name,n);
math=ma;
chinese=chin;
english=eng;
}
double getsum()
{
sum=chinese+english+math;
return sum;
}
double getaver()
{
average=getsum()/3;
return average;
}
friend void main();
};
void main()
{
cout<<"请选择您需要的操作!"<<endl;
cout<<"操作:"<<endl;
cout<<"(0)数据录入"<<endl;
cout<<"(1)增加人员"<<endl;
cout<<"(2)删除人员"<<endl;
cout<<"(3)修改数据"<<endl;
cout<<"查询:"<<endl;
cout<<"(4)按总成绩查询"<<endl;
cout<<"(5)按姓名查询"<<endl;
cout<<"(6)输出所有学生的数据"<<endl;
cout<<"成绩名词"<<endl;
cout<<"(7)按总分查询排名"<<endl;
cout<<"(8)按语文查询排名"<<endl;
cout<<"(9)按数学查询排名"<<endl;
cout<<"(y)按英语查询排名"<<endl;
cout<<"选择相关操作请输入相对的括号里的阿拉伯数字!"<<endl;
char p;char w;
stu *s[50];
ofstream *file[50];
int i=0;
int j=0;
bool flag2=0;
do
{
cin>>p;
if((p>='0'&&p<='10'))
flag2=1;
else
cout<<"指令错误!请重新输入:"<<endl;
}while(flag2==0);
do
{
switch(p)
{
case '0':
{
char c;
char name[20];double math,chinese,english;
do{
cout<<"请输入姓名"<<endl;
cin>>name;
cout<<"请输入数学成绩:"<<endl;
cin>>math;
cout<<"请输入语文成绩:"<<endl;
cin>>chinese;
cout<<"请输入外语成绩:"<<endl;
cin>>english;
file[j]=new ofstream("d:\\document",ios::ate);
*file[j]<<"姓名"<<name<<"数学成绩"<<math<<"语文成绩"<<chinese<<"外语成绩"<<english<<endl;
j++;
s[i]=new stu(name, math, chinese, english);
i++;
cout<<"数据录入成功,想继续录入吗(y/n)"<<endl;
cin>>c;
flag2=0;
do
{
if(c!='y'&&c!='n')
{
cout<<"指令错误!请重新输入!"<<endl;
cin>>c;
}
else
flag2=1;
}while(flag2==0);
}while(c=='y');
break;
}
case '4':
{
double t;char c;
do
{
int flag1=0;
cout<<"请输入你要查询学生的总成绩"<<endl;
cin>>t;
for(int q=0;q<i;q++)
{
if(s[q]->getsum()==t)
{
flag1=1;
cout<<"您要查询的学生是:"<<(*s[q]).name<<endl;
}
}
if(flag1==0)
cout<<"对不起!您要查询的学生不存在!"<<endl;
cout<<"您想继续查询吗?(y/n)"<<endl;
cin>>c;
if(c!='y'&&c!='n')
{
cout<<"指令错误!请重新输入!"<<endl;
cin>>c;
}
}
while(c=='y');
break;
}
case '5':
{
char n[20];int j=0;char c;
do{
int flag=0;
cout<<"请输入你要查询的学生姓名"<<endl;
cin>>n;
for(int j=0;j<i;j++)
{
if(strcmp(n,(*s[j]).name)==0)
{
flag=1;
cout<<"您要查询的学生是:"<<(*s[j]).name<<endl;
cout<<(*s[j]).name<<"的总成绩成绩是"<<(*s[j]).getsum()<<endl<<"平均成绩是:"<<(*s[j]).getaver()<<endl;
}
}
if(flag==0)
cout<<"对不起!您要查询的学生不存在!"<<endl;
cout<<"您想继续查询吗?(y/n)"<<endl;
cin>>c;
if(c!='y'&&c!='n')
{
cout<<"指令错误!请重新输入!"<<endl;
cin>>c;
}
}
while(c=='y');
break;
} 还有一部分。。
4. 面向对象程序设计课程设计
/*这是我一次作业写的,跟你的要求挺像的,给你吧。至于其他的,你自己写吧,类的定义和一些函数都有了,剩下的听简单的,相信你可以很快就写出来*/ #include <cctype> #include <cstring> #include <cstdlib> #include <fstream> #include <iostream> #include "Date.h" using namespace std; Date:: Date(void) : month(0), day(0), year(0), hour(0), minute(0), second(0) {} Date::Date (int month, int day, int year, int hour, int minute, int second) : month(month), day(day), year(year), hour(hour), minute(minute), second(second) {} void Date::setMonth(int& month) { this->month = month; } void Date::setDay(int& day) { this->day = day; } void Date::setYear(int& year) { this->year = year; } void Date::setHour(int& hour) { this->hour = hour; } void Date::setMinute(int& minute) { this->minute = minute; } void Date::setSecond(int& second) { this->second = second; } int Date::getMonth(void) const { return month; } int Date::getDay(void) const { return day; } int Date::getYear(void) const { return year; } int Date::getHour(void) const { return hour; } int Date::getMinute(void) const { return minute; } int Date::getSecond(void) const { return second; } bool Date::operator== (const Date &rhs) { if ( (this->getMonth() != rhs.getMonth()) || (this->getDay() != rhs.getDay()) || (this->getYear() != rhs.getYear()) || (this->getHour() != rhs.getHour()) || (this->getMinute() != rhs.getMinute()) || (this->getSecond() != rhs.getSecond()) ) { return false; } else { return true; } } bool Date::operator< (const Date &rhs) { if (this->getYear() != rhs.getYear()) { if (this->getYear() < rhs.getYear()) return true; else return false; } if (this->getMonth() != rhs.getMonth()) { if (this->getMonth() < rhs.getMonth()) return true; else return false; } if (this->getDay() != rhs.getDay()) { if (this->getDay() < rhs.getDay()) return true; else return false; } if (this->getHour() != rhs.getHour()) { if (this->getHour() < rhs.getHour()) return true; else return false; } if (this->getMinute() != rhs.getMinute()) { if (this->getMinute() < rhs.getMinute()) return true; else return false; } if (this->getSecond() < rhs.getSecond()) { return true; } else { return false; } } ostream &operator<<(ostream &stream, const Date &d) { stream << d.getMonth() << "/" << d.getDay() << "/" << d.getYear(); stream << " " << d.getHour() << ":" << d.getMinute() << ":" << d.getSecond(); return stream; } istream &operator>>(istream &stream, Date &d) { char buffer[10]; stream.getline(buffer, 4, '/'); int value = atoi (buffer); d.setMonth(value); stream.getline(buffer, 4, '/'); value = atoi (buffer); d.setDay(value); stream.getline(buffer, 6, ' '); value = atoi (buffer); d.setYear(value); stream.getline(buffer, 4, ':'); value = atoi (buffer); d.setHour(value); stream.getline(buffer, 4, ':'); value = atoi (buffer); d.setMinute(value); stream.getline(buffer, 4); value = atoi (buffer); d.setSecond(value); return stream; }
5. 《面向对象程序设计》课程设计模拟时钟程序
去繁存简,mfc timer消息处理 GDI画东西,必要的东西:
mfc 的 timer 一个.
dc 一个.
需要用到的函数
settimer() 定时100毫秒产生一个timer消息出发ontimer, 在ontimer里面获取当前系统时间 systemtime;
如果时间改变了用dc重画时钟界面, 最简单的 moveto lineto.
6. 《面向对象分析与设计》课程设计: 课程设计题目:图书管理系统
一、课程设计题目: 图书管理系统 二、目的与要求:1、目的:1)要求学生达到熟练掌握面向对象的思想和机制。 2)掌握面向对象分析与设计的基本思路和方法 3)能够利用所学的基本知识和技能,解决简单的面向对象的分析与设计问题2、要求:1)要求利用面向对象的方法及思想完成系统的分析与设计 2)要求在分析与设计的过程中,建立清晰的类层次。 4)建立用况模型(用况图),并给出主要用况的描述 5)建立静态模型(类图) 6)建立动态模型 主要对象的顺序图 主要对象的状态机图7)设计系统设计人机界面设计 三、系统的功能要求 该系统可以实现图书的借阅、还书,图书库存管理等功能,节省了管理成本,节约了管理费用,加快了借阅速度。主要包括帐号管理、图书库存管理、图书借阅管理、还书管理等项内容 四、课程设计存档说明 每组交一份课程设计报告。 封面 1,封面包括:课程设计题目、组名、组员姓名、班级、设计时间等信息。 正文 ,2,具体由以下几部分组成: 1)项目的名称 2)项目的主题、设计目的 3)系统的功能需求 4)需求模型 5)系统分析 6)系统设计包括:问题域的设计和界面部分的设计 7)本次设计的收获 8)设计报告中有待改进提高之处 9)设计实践过程中的自我感想。 ~~~
7. 面向对象课程设计VC++ 模拟时钟程序
你也说了 是24小时计时法
那12点肯定是12点啦
楼主是想问24点时候是24点还是0点吧,
很负责的告版诉你,是0点
因为权24进制中,满24该进到下一位了,剩下应该是0
就像10进制中的满10进1 10已经进到十位了,个位现在是0啦……
8. C++课程设计,单部电梯的模拟运行,界面有无皆可!
#include <stdio.h>
#include <stdlib.h>
#define GoingUp 1//匀速上升
#define GoingDown 2//匀速下降
#define SpeedUp 3//加速上升
#define SpeedDown 4//加速下降
#define SlowUp 5//减速上升准备停靠
#define SlowDown 6//减速下降准备停靠
#define Idle 7//空闲
#define Stop 8//停止且已关门
#define DoorOpen 9//停止且门已打开
#define DoorOpening 10
#define DoorCloseing 11
#define CloseTest 40 //电梯关门测试时间
#define OverTime 300 //电梯停候超时时间
#define Accelerate 15 //加速时间
#define UpTime 51 //上升时间
#define DownTime 61 //下降时间
#define UpDecelerate 14 //上升减速
#define DownDecelerate 23 //下降减速
#define DoorTime 20 //开门关门时间
#define InOutTime 25 //进出电梯时间
#define MaxTime 10000
#define MaxFloor 5
#define BaseFloor 1
typedef struct Person{
int Id;
int OutFloor;
int GiveupTime;
struct Person* next;
}Person;
typedef struct Activity{
int time;
void(*fn)(void);
struct Activity* next;
}Activity;
typedef struct Person_Ele{
int Id;
struct Person_Ele* next;
}Person_Ele;
int AddQueue(int floor,struct Person* p);
void AddAct(int time,void(*fn)(void));
void TestPeople();
void DoTime();
void Input(void);
//以下函数与电梯决策有关
void testinout(void);
void doclosedoor(void);
void doopendoor(void);
void doout(void);
void doin(void);
void doup(void);
void dodown(void);
void domove(void);
void doslow(void);
void tofirst();
int GetWhere(void);
int Time=0;
int CallUp[MaxFloor]={0,};
int CallDown[MaxFloor]={0,};
int CallCar[MaxFloor]={0,};
int Floor=BaseFloor;
int State=Idle;
int PersonId=0;
Activity activity={0,NULL,NULL};
Person_Ele Stack[5]={0,};
Person Queue[5]={0,};
void Init() {int i;
for(i=0;i<MaxFloor;i++){
Stack[i].next=NULL;
Queue[i].next=NULL;
}
activity.next=NULL;
}
int main(){
Init();
Input();
DoTime();
return 0;
}
int AddQueue(int floor,Person* p){//加入相应层的客户等待队列
Person* tmp=&Queue[floor];//这始终加在链表的最后一位,
while(tmp->next!=NULL){
tmp=tmp->next;
}
tmp->next=p;
return 0;
}
void AddAct(int time,void(*fn)(void)){//将一个活动加入定时器,时间到了会调用这个函数
time=Time+time; //这个函数参数必须是void,返回值也必须是void
struct Activity* act;
act=(struct Activity*)malloc(sizeof(struct Activity));
act->next=NULL;
act->fn=fn;
act->time=time;
struct Activity* p=&activity;
while(p->next!=NULL){
if(p->next->time>time)
break;
p=p->next;
}
act->next=p->next;
p->next=act;
}
void TestPeople(){//这是检测每层队列是否有人放弃,有人放弃就将他踢出队列
int i;//这个函数每个时间都会被调用,效率相对较低
for(i=0;i<MaxFloor;i++){
Person* p=Queue[i].next;
Person* q=&Queue[i];
if(p==NULL)
continue;
while(p!=NULL){
if(p->GiveupTime<=Time){
if(Floor=i&&(State>=Idle))
break;
q->next=p->next;
printf("用户%d放弃了等待!\n",p->Id);
free(p);
p=q->next;
continue;
}
q=p;
p=p->next;
}
}
}
void Input(void){//输入人员信息,这个需要手动调用一次,之后就根据定时器调用了
Person* p = (Person*)malloc(sizeof(Person));
int infloor,outfloor,giveuptime,intertime;
while(1){
printf("请输入用户的起始楼层:");
scanf("%d",&infloor);
printf("请输入用户的目标的楼层:");
scanf("%d",&outfloor);
printf("请输入用户的最长容忍时间:");
scanf("%d",&giveuptime);
printf("请输入下一个用户的到来时间:");
scanf("%d",&intertime);
if(!(infloor<0||infloor>MaxFloor-1||outfloor<0||outfloor>MaxFloor-1)&&(infloor!=outfloor))
break;
printf("错误的用户信息录入!\n");
}
p->Id=PersonId++;
p->GiveupTime=giveuptime+Time;
p->next=NULL;
p->OutFloor=outfloor;
if(outfloor>infloor)
CallUp[infloor]=1;
else
CallDown[infloor]=1;
AddQueue(infloor,p);
AddAct(intertime,Input);
}
void testinout(void){//检测有无人进出
if(Queue[Floor].next||Stack[Floor].next)
AddAct(CloseTest,testinout);
else{
State=DoorCloseing;
CallUp[Floor]=0;
CallDown[Floor]=0;
CallCar[Floor]=0;
AddAct(DoorTime,doclosedoor);
}
}
void doclosedoor(void){//电梯门关了
printf("电梯门关了\n");
State=Stop;
}
void doopendoor(void){//打开电梯门
printf("电梯门开了\n");
State=DoorOpen;//门打开了
AddAct(CloseTest,testinout);
if(Stack[Floor].next)
AddAct(InOutTime,doout);
else{//没人出,就看有没有进的
if(Queue[Floor].next)
AddAct(InOutTime,doin);
}
}
void doout(void){
//根据栈出人,如果没有看是否有人进
if(Stack[Floor].next){
Person_Ele* p=Stack[Floor].next;
Stack[Floor].next=p->next;
;//显示信息
printf("用户%d走出电梯\n",p->Id);
free(p);
}
if(Stack[Floor].next){
AddAct(InOutTime,doout);
}else{
if(Queue[Floor].next)
AddAct(InOutTime,doin);
}
}
void doin(void){//人进入电梯,这里不用关电梯门它会定时关的
Person* p=Queue[Floor].next;
if(p){
Queue[Floor].next=p->next;
Person_Ele* pe=(Person_Ele*)malloc(sizeof(Person_Ele));
int in=p->OutFloor;
CallCar[in]=1;//置位请求
pe->next=Stack[in].next;
pe->Id=p->Id;
Stack[in].next=pe;
printf("用户%d走入电梯\n",p->Id);
free(p);
}
if(Queue[Floor].next){
AddAct(InOutTime,doin);
}
}
int GetWhere(void){
static int old=0;//保存上一次电梯的方向,保证电梯尽可能在一个方向走
int isup=0,isdown=0;
int i;
for(i=Floor+1;i<MaxFloor;i++){
if(CallDown[i]||CallUp[i]||CallCar[i])
isup=1;
}
for(i=Floor-1;i>=0;i--){
if(CallDown[i]||CallUp[i]||CallCar[i])
isdown=1;
}
if(isup==0&&isdown==0){
return 0;
}
if(old==0){
if(isdown) old=GoingDown;
if(isup) old=GoingUp;
return old;
}
if(old==GoingUp&&isup)
return old;
else if(old==GoingDown&&isdown)
return old;
else if(isdown)
old=GoingDown;
else if(isup)
old=GoingUp;
else
printf("在选择方向时发生错误!\n");
return old;
}
void tofirst(void){//去第一层
if(State!=Idle||Floor==BaseFloor)
return;
printf("长时间没人请求电梯!将进入%d层\n",BaseFloor);
CallCar[BaseFloor]=2;//给电梯一个虚拟的去1层的请求,这并不会开门
}
void doslow(void){//电梯停了
printf("电梯停了,当前层是%d\n",Floor);
State=Stop;
}
void doup(void){
Floor++;
printf("电梯正在上升!现已到了%d层!\n",Floor);
if(CallDown[Floor]||CallUp[Floor]||CallCar[Floor]){
State=SlowUp;
AddAct(UpDecelerate,doslow);
}else{
if(Floor==MaxFloor-1){
State=SlowUp;
AddAct(UpDecelerate,doslow);
}else{
AddAct(UpTime,doup);
}
}
}
void dodown(void){
Floor--;
printf("电梯正在下降!现已到了%d层!\n",Floor);
if(CallUp[Floor]||CallDown[Floor]||CallCar[Floor]){
State=SlowDown;
AddAct(DownDecelerate,doslow);
}else{
if(Floor==0){
State=SlowDown;
AddAct(DownDecelerate,doslow);
}else{
AddAct(DownTime,dodown);
}
}
}
void domove(void){//加速完成,将进入正常速度
if(State==SpeedUp){
printf("电梯已加速上升!\n");
State=GoingUp;
AddAct(UpTime,doup);
}else{
printf("电梯已加速下降!\n");
State=GoingDown;
AddAct(DownTime,dodown);
}
}
void Controler(void){
if(State==Idle||State==Stop){
if(CallUp[Floor]||CallDown[Floor]||CallCar[Floor]){
//当前层有请求,需要开门进出
if(CallCar[BaseFloor]==2){
CallCar[BaseFloor]=0;
State=Idle;
printf("现在在%d层,无人请求电梯!\n",BaseFloor);
return;
}
State=DoorOpening;
AddAct(DoorTime,doopendoor);
}
else{
//当前层无请求,判断其他层请求
int whitch=GetWhere();
if(whitch==GoingUp){
State=SpeedUp;
AddAct(Accelerate,domove);
}else if(whitch==GoingDown){
State=SpeedDown;
AddAct(Accelerate,domove);
}else{
State=Idle;
if(Floor!=BaseFloor)
AddAct(OverTime,tofirst);
}
}
}
//否则电梯忙碌
return;
}
void DoTime(){
//此函数用于模拟时钟
while(1){
if(Time>MaxTime)
return;
TestPeople();//两个始终都会被调用的函数
Controler();
struct Activity* p=activity.next;
if(p==NULL){
Time=MaxTime;
}
if(p&&Time>=p->time){//取出活动队头的,检测定时是否到了
activity.next=p->next;
p->fn();
free(p);
}
Time++;
}
}