#include <string>
#include<iostream>
using namespace std;
#include<time.h>
const int Password = 13002506;
typedef struct Node
{
int no;
char owner[20];//以owner作為收費員的代寫
int kind;//車輛型別1,2,3數字輸入;
float journey;//如果輸入為1,2,3時,加入journey進行計算,#define journey 為 jour
float money;
struct Node *next;
}Cars;
int pass( )
{
int count, pw;
count = 0;
while (count < 3)
{
cout<<endl;
cout<<"請您輸入操作密碼:";
cin>>pw;
if (pw != Password)
{
count++;
cout<<"操作密碼錯誤!"<<endl;
}
else
{
break;
}
}
if (count== 3)
{
count=0;
}
else{
count=1;
}
return count;
}
int menu( )
{
int selected;
while (true)
{
cout<<endl;
cout<<"1.請輸入車型: "<<endl;//輸入車型,輸入路程,進行計算,進行顯示,退出程式
cout<<"2.請輸入路程: "<<endl;
cout<<"3.計算繳費: "<<endl;
cout<<"4.車輛資訊顯示: "<<endl;
cout<<"0.退出程式 "<<endl<<endl;//與一般的1,2,3,4,5不一樣
cout<<"請輸入你的選擇:(0~4) ";
cin>>selected;
if (selected > 4 ||
selected < 0)
{
cout<<"輸入錯誤,請您重新輸入!"<<endl;
}
else
{
break;
}
}
return selected;
}
void input(int &n, char *o,int &k,float &j)
{
cout<<endl;
cout<<"1.請輸入車輛編號: ";
cin>>n;//這里是跟著參考改變的功能
cout<<"2.請輸入收費員姓名: ";
cin>>o;
cout<<"3.請輸入車輛型別: ";
cin>>k;
cout<<"4.請輸入行駛路程: ";
cin>>j;
float calCharge(float journey)
{
float money;
money = 0;
if (kind=1)
{
money = journey * 0.5;
}
if (kind=2)
{
money = journey * 0.4;
}
if (kind=3)
{
money = journey * 0.3;
}
return money;
}
int main(int argc,char* argv[])
{
int selected;
Cars *head, *s;
head = new Cars();
head->next= NULL;
cout<<"歡迎使用高速公路計費系統!"<<endl<<endl;
if (!pass())
{
cout<<"你已聯系3次輸入錯誤!系統即將退出..."<<endl;
system("pause");
return 0;
}
while (true)
{
switch (selected = menu())
{
case 1:
s = new Cars();//系統在開始的時候,貼著左側,習慣性寫字的順序,不是隨心所欲的編程
input(s->no, s->owner, s->kind,s->journey);
s->next = head->next;
head->next = s;
break;
case 2:
s = head->next;
while (s)
{
s->money = calCharge(s->journey);
s = s->next;
}
cout << "計費完成"<<endl;
break;
case 3:
s = head->next;
printf("列印車輛資訊:\n");
printf("------------------------------------------------\n");
printf("編號 收費人員 車型 路程 費用\n");
while (s)
{
printf("%-10d%-16s%-10d%-10.2f%-10.2f\n",
s->no, s->owner,s->kind, s->journey,s->money);
s = s->next;
}
printf("------------------------------------------------\n");
break;
default:
break;
}
if (selected==0)
{
cout<<"歡迎下次使用!再見…"<<endl;
break;
}
}
system("pause");
cout<<"請輸入命令符:";
char chCmd[256] = {0};//定義一個字符陣列
while(true)
{
cin.getline(chCmd,255);//等待用戶輸入
if(chCmd[0] == '?')
{
//輸出幫助資訊
cout<<"輸入數字1顯示系統時間,輸入數字2顯示系統日期,輸入字母e退出系統!"<<endl;
}
else if(chCmd[0] == 'e')
{
return 0;
}
else if(chCmd[0] == '1')
{
time_t nowTime;
time(&nowTime);//獲取系統時間
struct tm *sysTime = localtime(&nowTime);//轉換為系統時間
cout<<"系統時間:"<<sysTime->tm_hour<<":"
<<sysTime->tm_min<<":"<<sysTime->tm_sec<<endl;//輸出資訊
}
else if(chCmd[0] == '2')
{
time_t nowTime;
time(&nowTime);//獲取系統時間
struct tm *sysTime = localtime(&nowTime);//轉換為系統時間
cout<<"系統時間:"<<1900 + sysTime->tm_year<<"-"<<
sysTime->tm_mon+1<<"-"<<sysTime->tm_mday<<endl;//輸出資訊
}
cout<<"請輸入命令符:"<<endl;
}
return 0;
}
uj5u.com熱心網友回復:
長得是丑了點,還請各位莫見怪uj5u.com熱心網友回復:
void input(int &n, char *o,int &k,float &j){
cout<<endl;
cout<<"1.請輸入車輛編號: ";
cin>>n;//這里是跟著參考改變的功能
cout<<"2.請輸入收費員姓名: ";
cin>>o;
cout<<"3.請輸入車輛型別: ";
cin>>k;
cout<<"4.請輸入行駛路程: ";
cin>>j; //這里少了}
float calCharge(float journey)
{
float calCharge(float journey)
{
float money;
money = 0;
if (kind=1) //這個kind沒有定義
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/108664.html
標籤:基礎類
上一篇:大家好,下面一段代碼中紅色一句有錯誤,請指正,謝謝!
下一篇:求助貼
