|
|
我哥帮我做了个课设,用的C++
可我想改为C的,遇到了个问题
/****************************************
* file name : drugManager.cpp
* author : Andrew
* last modify : 11/27/2007
***************************************/
#include<stdio.h>
const int N = 10;
struct drug
{
int number;
char kind;
float price;
int amount;
double totalPrice;
};
void _author(void);
void _mainMenu(drug *drugs);
void _initDrug(drug *drugs);
void _checkNumber(drug *drugs, const int &i);
void _locate(drug *drugs);
void _subLocate(drug *drugs);
void _update(drug *drugs);
void _subUpdate(drug *drugs);
void _insert(drug *drugs, int &N);
void _subInsert(drug *drugs, int &N);
void _delete(drug *drugs);
void _subDelete(drug *drugs);
void _statistMenu(drug *drugs);
void _viewPrice(drug *drugs);
void _sortMenu(drug *drugs);
void _upSort(drug *drugs);
void _downSort(drug *drugs);
void _exit(drug *drugs);
int main(int argc, char **argv)
{
_author();
drug *drugs = new drug[N];
_initDrug(drugs);
return (0);
}
void _author(void)
{
cout<<"My name is Song Zhenyuan"<<endl;
cout<<"My number is 123"<<endl;
cout<<"I am 19 years old. "<<endl<<endl;
}
//*************************************************************
void _mainMenu(drug *drugs)
{
system("cls");
cout<<" DRUG MANAGE SYSTEM "<<endl;
cout<<" "<<endl;
cout<<"1. Key in 'L' to locate the imformation by drug number."<<endl;
cout<<"2. Key in 'U' to update the imformation by drug number."<<endl;
cout<<"3. Key in 'D' to delete the imformation by drug number."<<endl;
cout<<"4. Key in 'S' to view the Statistic imformations. "<<endl;
cout<<"5. Key in 'E' to exit the system."<<endl;
cout<<endl<<"Select one option you want:";
char choose = '\0'
int aCase = 0;
cin>>choose;
if (choose=='L' || choose=='l') aCase = 1;
if (choose=='U' || choose=='u') aCase = 2;
if (choose=='D' || choose=='d') aCase = 3;
if (choose=='S' || choose=='s') aCase = 4;
if (choose=='E' || choose=='e') aCase = 5;
switch (aCase)
{
case 1: _locate(drugs); break;
case 2: _update(drugs); break;
case 3: _delete(drugs); break;
case 4: _statistMenu(drugs); break;
case 5: _exit(drugs); break;
default: cout<<"The option can not find"<<endl;
cout<<" lease put 'enter' key try again.";
char c;
cin.get(c);
cin.get(c);
if(c=='\n') _mainMenu(drugs);
break;
}
}
//*************************************************************
void _initDrug(drug *drugs)
{
cout<<" lease enter the informations of drugs."<<endl;
cout<<"************************"<<endl;
for(int i=0; i<N; i++ )
{
cout<<endl<<" lease enter the drugs of "<<i+1<<":"<<endl;
_checkNumber(drugs, i);
cout<<"choose the drug kind:"<<endl;
char k = '\0'
cout<<"enter C is Chinese traditional medicine"<<endl;
cout<<"enter W is Western medicine"<<endl;
cin>>k;
if (k=='c' || k=='C') drugs.kind = 'C'
if (k=='w' || k=='W') drugs.kind = 'W'
cout<<"Drug price(yuan):";
cin>>drugs.price;
cout<<"Drug amount:";
cin>>drugs.amount;
drugs.totalPrice = drugs.price * drugs.amount;
cout<<endl<<"************************"<<endl;
}
cout<<"INPUT COMPLETE"<<endl;
cout<<" lease put 'enter' key to goto main menu";
char c;
cin.get(c);
cin.get(c);
if(c=='\n') _mainMenu(drugs);
}
void _checkNumber(drug *drugs, const int &i)
{
cout<<"Drug number: ";
drugs.number = -1;
cin>>drugs.number;
for(int j=0; j<i; j++)
{
if(drugs.number == drugs[j].number)
{
cout<<"Existing drug number, please enter again."<<endl;
_checkNumber(drugs, i);
}
}
}
//*************************************************************
void _locate(drug *drugs)
{
system("cls");
cout<<" DRUG MANAGE SYSTEM LOCATE "<<endl;
cout<<" "<<endl;
cout<<"1. Key in 'L' to locate the imformation by drug number."<<endl;
cout<<"2. Key in 'R' to return the main menu. "<<endl;
cout<<endl<<"Select one option you want:";
char choose = '\0'
int aCase = 0;
cin>>choose;
if (choose=='L' || choose=='l') aCase = 1;
if (choose=='R' || choose=='r') aCase = 2;
switch (aCase)
{
case 1: _subLocate(drugs); break;
case 2: _mainMenu(drugs); break;
default: cout<<"The option can not find"<<endl;
cout<<" lease put 'enter' key try again.";
char c;
cin.get(c);
cin.get(c);
if(c=='\n') _locate(drugs);
break;
}
}
void _subLocate(drug *drugs)
{
system("cls");
cout<<"Existing drug numbers:"<<endl;
for (int i=0; i<N; i++)
{
if (drugs.number!=-1)
cout<<"drug number:"<<drugs.number<<endl;
}
cout<<endl;
int x;
cout<<"Choose the number which you want to see: ";
cin>>x;
for (i=0; i<N; i++)
{
if (x==drugs.number)
{
if(drugs.kind = 'C')
cout<<"The drug kind:"<<"Chinese traditional medicine"<<endl;
else
cout<<"The drug kind: "<<"Western medicine"<<endl;
cout<<"Drug price: "<<drugs.price<<" yuan"<<endl;
cout<<"Drug amount: "<<drugs.amount<<endl;
cout<<"Drug total price: "<<drugs.totalPrice<<" yuan"<<endl;
break;
}
}
cout<<endl<<" lease put 'enter' key to goto main menu";
char c;
cin.get(c);
cin.get(c);
if(c=='\n') _mainMenu(drugs);
}
//*************************************************************
void _update(drug *drugs)
{
system("cls");
cout<<" DRUG MANAGE SYSTEM UPDATE "<<endl;
cout<<" "<<endl;
cout<<"1. Key in 'U' to update the imformation by drug number."<<endl;
cout<<"2. Key in 'R' to return the main menu. "<<endl;
cout<<endl<<"Select one option you want:";
char choose = '\0'
int aCase = 0;
cin>>choose;
if (choose=='U' || choose=='u') aCase = 1;
if (choose=='R' || choose=='r') aCase = 2;
switch (aCase)
{
case 1: _subUpdate(drugs); break;
case 2: _mainMenu(drugs); break;
default: cout<<"The option can not find"<<endl;
cout<<" lease put 'enter' key try again.";
char c;
cin.get(c);
cin.get(c);
if(c=='\n') _update(drugs);
break;
}
}
void _subUpdate(drug *drugs)
{
system("cls");
cout<<"Existing drug numbers:"<<endl;
for (int i=0; i<N; i++)
{
if (drugs.number!=-1)
cout<<"drug number:"<<drugs.number<<endl;
}
cout<<endl;
int x;
cout<<"Choose the number which you want to change : ";
cin>>x;
for (i=0; i<N; i++)
{
if (x==drugs.number)
{
cout<<"choose the drug kind:"<<endl;
char k = '\0'
cout<<"enter C is Chinese traditional medicine"<<endl;
cout<<"enter W is Western medicine"<<endl;
cin>>k;
if (k=='c' || k=='C') drugs.kind = 'C'
if (k=='w' || k=='W') drugs.kind = 'W'
cout<<"Drug price:";
cin>>drugs.price;
cout<<"Drug amount:";
cin>>drugs.amount;
drugs.totalPrice = drugs.price * drugs.amount;
break;
}
}
cout<<"UPDATE SUCCEED"<<endl;
cout<<" lease put 'enter' key to goto main menu";
char c;
cin.get(c);
cin.get(c);
if(c=='\n') _mainMenu(drugs);
}
//*************************************************************
void _delete(drug *drugs)
{
system("cls");
cout<<" DRUG MANAGE SYSTEM DELETE "<<endl;
cout<<" "<<endl;
cout<<"1. Key in 'D' to delete the imformation by drug number."<<endl;
cout<<"2. Key in 'R' to return the main menu."<<endl;
cout<<endl<<"Select one option you want:";
char choose = '\0'
int aCase = 0;
cin>>choose;
if (choose=='D' || choose=='d') aCase = 1;
if (choose=='R' || choose=='r') aCase = 2;
switch (aCase)
{
case 1: _subDelete(drugs); break;
case 2: _mainMenu(drugs); break;
default: cout<<"The option can not find"<<endl;
cout<<" lease put 'enter' key try again.";
char c;
cin.get(c);
cin.get(c);
if(c=='\n') _delete(drugs);
break;
}
}
void _subDelete(drug *drugs)
{
system("cls");
cout<<"Exit drug numbers:"<<endl;
for (int i=0; i<N; i++)
{
if (drugs.number!=-1)
cout<<"drug number:"<<drugs.number<<endl;
}
cout<<endl;
int x;
cout<<"Choose the number which you want to delete: ";
cin>>x;
for (i=0; i<N; i++)
{
if (x==drugs.number)
{
drugs.number = -1;
drugs.kind = '\0'
drugs.price = 0;
drugs.amount = 0;
drugs.totalPrice = 0;
break;
}
}
cout<<"DELETE SUCCEED"<<endl;
cout<<" lease put 'enter' key to goto main menu";
char c;
cin.get(c);
cin.get(c);
if(c=='\n') _mainMenu(drugs);
}
//*************************************************************
void _statistMenu(drug *drugs)
{
system("cls");
cout<<" DRUG STATIST MENU "<<endl;
cout<<" "<<endl;
cout<<"1. Key in 'P' to view the statist price of drugs."<<endl;
cout<<"2. Key in 'S' to sort the drugs by unit price. "<<endl;
cout<<"3. Key in 'R' to return the main menu."<<endl;
cout<<endl<<"Select one option you want:";
char choose = '\0'
int aCase = 0;
cin>>choose;
if (choose=='P' || choose=='p') aCase = 1;
if (choose=='S' || choose=='s') aCase = 2;
if (choose=='R' || choose=='r') aCase = 3;
switch (aCase)
{
case 1: _viewPrice(drugs); break;
case 2: _sortMenu(drugs); break;
case 3: _mainMenu(drugs); break;
default: cout<<"The option can not find"<<endl;
cout<<" lease put 'enter' key try again.";
char c;
cin.get(c);
cin.get(c);
if(c=='\n') _statistMenu(drugs);
break;
}
}
void _viewPrice(drug *drugs)
{
system("cls");
cout<<" DRUG STATIST VIEW "<<endl;
cout<<" "<<endl;
double tPrice = 0;
double cTotalPrice = 0;
double wTotalPrice = 0;
for (int i=0; i<N; i++)
{
if (drugs.number != -1 && drugs.kind == 'C')
{
cTotalPrice += drugs.totalPrice;
}
if (drugs.number != -1 && drugs.kind == 'W')
{
wTotalPrice += drugs.totalPrice;
}
}
tPrice = cTotalPrice + wTotalPrice;
cout<<"The price of total drugs is "<<tPrice<<" yuan"<<endl;
cout<<"The price of Chinese drugs is "<<cTotalPrice<<" yuan"<<endl;
cout<<"The price of Westen drugs is "<<wTotalPrice<<" yuan"<<endl;
cout<<endl;
cout<<endl<<" lease put 'enter' key to goto statist menu.";
char c;
cin.get(c);
cin.get(c);
if(c=='\n') _statistMenu(drugs);
}
void _sortMenu(drug *drugs)
{
system("cls");
cout<<" DRUG UNIT PRICE SORT "<<endl;
cout<<" "<<endl;
cout<<"1. Key in 'E' to sort the drug unit from expensive to cheap."<<endl;
cout<<"2. Key in 'C' to sort the drug unit from cheap to expensive."<<endl;
cout<<"3. Key in 'R' to return the statist menu. "<<endl;
cout<<endl<<"Select one option you want:";
char choose = '\0'
int aCase = 0;
cin>>choose;
if (choose=='E' || choose=='e') aCase = 1;
if (choose=='C' || choose=='c') aCase = 2;
if (choose=='R' || choose=='r') aCase = 3;
switch (aCase)
{
case 1: _upSort(drugs); break;
case 2: _downSort(drugs); break;
case 3: _statistMenu(drugs); break;
default: cout<<"The option can not find"<<endl;
cout<<" lease put 'enter' key try again.";
char c;
cin.get(c);
cin.get(c);
if(c=='\n') _sortMenu(drugs);
break;
}
}
void _downSort(drug *drugs)
{
system("cls");
int num = 0;
drug temp;
for (int i=0; i<N; i++)
{
if (drugs.number != -1) num += 1;
}
for (int j=0; j<num-1; j++)
{
for (i=0; i<num-1-j; i++)
{
if (drugs.price>drugs[i+1].price)
{
temp = drugs;
drugs = drugs[i+1];
drugs[i+1] = temp;
}
}
}
cout<<"The drug unit from expensive to cheap."<<endl;
for (i=0; i<N; i++)
{
if(drugs.number != -1)
cout<<i+1<<". The drug number: "<<drugs.number<<endl;
}
cout<<endl;
cout<<" lease put 'enter' key to return sort menu.";
char c;
cin.get(c);
cin.get(c);
if(c=='\n') _sortMenu(drugs);
}
void _upSort(drug *drugs)
{
system("cls");
int num = 0;
drug temp;
for (int i=0; i<N; i++)
{
if (drugs.number != -1) num += 1;
}
for (int j=0; j<num-1; j++)
{
for (i=0; i<num-1-j; i++)
{
if (drugs.price<drugs[i+1].price)
{
temp = drugs;
drugs = drugs[i+1];
drugs[i+1] = temp;
}
}
}
cout<<"The drug unit from cheap to expensive."<<endl;
for (i=0; i<N; i++)
{
if(drugs.number != -1)
cout<<i+1<<". The drug number: "<<drugs.number<<endl;
}
cout<<endl;
cout<<" lease put 'enter' key to return sort menu.";
char c;
cin.get(c);
cin.get(c);
if(c=='\n') _sortMenu(drugs);
}
//*************************************************************
void _exit(drug *drugs)
{
delete []drugs;
cout<<endl<<"Thanks for using this system. "<<endl;
cout<<"Copyright by Andrew 2007."<<endl<<endl;
}
//*************************************************************
void _mainMenu(drug *drugs);
void _initDrug(drug *drugs);
void _checkNumber(drug *drugs, const int &i);
void _locate(drug *drugs);
void _subLocate(drug *drugs);
void _update(drug *drugs);
void _subUpdate(drug *drugs);
void _insert(drug *drugs, int &N);
void _subInsert(drug *drugs, int &N);
void _delete(drug *drugs);
void _subDelete(drug *drugs);
void _statistMenu(drug *drugs);
void _viewPrice(drug *drugs);
void _sortMenu(drug *drugs);
void _upSort(drug *drugs);
void _downSort(drug *drugs);
void _exit(drug *drugs);
这些都提示语法错误,这是为什么啊 |
|