電梯面向對象課程設計
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++;
}
}