答案:列车车次信息查询与检索系统
#include <string.h>
#include <malloc.h>
#include <iostream.h>
#include <conio.h>
typedef struct node
{ char n[20];
char ccnum[20];
char time[10];
struct node *next;
}NODE;
class employee
{
private:
NODE *p;
NODE *q;
NODE *t;
public:
employee(NODE *m);
void add();
void printall();
void print();
void deleteall();
void edit();
void del();
void tongji()
{
int sm=0;
NODE *k;
k=new NODE;
k=p=q;
char n[20];
cout<<"请输入站名:"<<endl;
cin>>n;
while (n)
{
k=p;
p=p->next;
if(p==t)
{
if(strcmp(q->n,n)==0)
{
sm++;
}
break;
}
if(strcmp(p->n,n)==0)
{
sm++;
}
}
if(sm==0) cout<<"查无次车"<<endl;
cout<<"统计车次数目为:"<<sm<<endl;
}
};
employee::employee(NODE *m)
{
t=p=m;
}
void employee::del()
{
NODE *k;
k=new NODE;
k=p=q;
char n[20];
cout<<"请输入车次号码:"<<endl;
cin>>n;
while (p!=t&&(strcmp(p->ccnum,n)!=0)!=0)
{k=p;
p=p->next;
}
if (p==t)
{cout<<"查无此车!!"<<endl;
}
else
{if (p==q)
q=q->next;
else
k->next=p->next;
free(p);
}
}
void employee::print()
{
p=q;
char n[20];
cout<<"请输入车次号码:"<<endl;
cin>>n;
while (p!=t&&(strcmp(p->ccnum,n)!=0)!=0)
{p=p->next;
}
if (p==t)
{cout<<"查无此车!!"<<endl;
}
else
{ cout<<"经过站点名称:"<<p->n<<endl;
cout<<"车次号码:"<<p->ccnum<<endl;
cout<<"发车时间:"<<p->time<<endl;
}
cout<<"按任意键返回!!"<<endl;
}
void employee::edit()
{
p=q;
char n[20];
cout<<"请输入车次号码:"<<endl;
cin>>n;
while (p!=t&&(strcmp(p->ccnum,n)!=0)!=0)
{p=p->next;
}
if (p==t)
{cout<<"查无此车!!"<<endl;
}
else
{cout<<"经过站点名称";
cin>>p->n;
cout<<"车次号码:";
cin>>p->ccnum;
cout<<"发车时间:";
cin>>p->time;
}
cout<<"按任意键返回!!"<<endl;
}
void employee::add()
{
q= new NODE;
q->next=p;
p=q;
cout<<"经过站点名称:";
cin>>q->n;
cout<<"车次号码:";
cin>>q->ccnum;
cout<<"发车时间:";
cin>>q->time;
}
void employee::printall()
{
p=q;
while (q!=t)
{
cout<<"经过站点:"<<q->n<<endl;
cout<<"车次号码:"<<q->ccnum<<endl;
cout<<"开车时间:"<<q->time<<endl;
q=q->next;
}
q=p;
}
void employee::deleteall()
{
while (q!=t)
{p=q;
q=q->next;
free(p);
}
cout<<"所有信息已删除!" ;
}
void display()
{
cout<<"\n 欢迎使用本系统 endl;
cout<<"\n "<<endl;
cout<<"\n 1:增加车次信息!"<<endl;
cout<<"\n 2:修改车次信息!"<<endl;
cout<<"\n 3:查找车次!"<<endl;
cout<<"\n 4:显示车次信息!"<<endl;
cout<<"\n 5:删除车次信息!"<<endl;
cout<<"\n 6:删除所有车次信息!"<<endl;
cout<<"\n 7:列车统计"<<endl;
cout<<"\n 8:退出!"<<endl;
cout<<"\n "<<endl;
}
void main()
{
int j;
char n[20],rna[10];
NODE *pa;
char i;
pa=(NODE*)malloc(sizeof(struct node));
display();
employee a(pa);
while(i=getch())
{
switch(i)
{
case'1':a.add();getch();display();break;
case'2':a.edit();getch();display();break;
case'3':a.print();getch();display();break;
case'4':a.printall();getch();display();break;
case'5':a.del();getch();display();break;
case'6':a.deleteall();getch();display();break;
case'7':a.tongji();getch();display();break;
case'8':cout<<"谢谢使用本系统!"<<endl;goto end;}
}
end: ;
}
最简单的Hello World
#include<stdio.h>
#include<stdlib.h>
int main(){
printf("Hello World!/n");
return 0;
}
#include<iostream>
using namespace std;
void main()
{
int a;
cin>>a;
cout<<a<<endl;
}
输入:1234
输出:1234
上一个:C++中换行符/n与endl有什么区别?
下一个:c++我找上打的错了77个