64,683
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std ;
//定义类book
class book
{
public :
int num ;
double price ;
book* next ;
} ;
//声明全局变量
book* head = NULL ;
//声明函数
void creat (book* head) ;
void display (book* head) ;
void insert (book* head) ;
void del (book *head) ;
char dis_func ( ) ;
void choi (char choice);
int number (book *head) ;
bool check ( ) ;
//主函数main ( )
int main ( )
{
char choice = dis_func ( ) ;
cout << choice;
choi (choice) ;
}
//函数定义
char dis_func ( )
{
char choice ;
system ("cls") ;//------------------他把你的结果清屏了
cout << "1.重建图书 2.显示图书 3.插入图书 4.删除图书 5.图书数目 q.退出" << endl ;
cout << "请输入你的选择:" ;
cin >> choice;
cin.ignore(1024,'\n');
return choice;
}
void choi (char choice)
{
switch (choice)
{
case '1' :creat (head) ;
break ;
case '2' :display (head);
system("pause");
break ;
case '3' :insert (head) ;
break ;
case '4' :del (head) ;
break ;
case '5' :cout << "图书数目:" << number (head) << endl ;
choi(dis_func ( ) ) ;
break ;
case 'q' :exit (0) ;
break ;
default :
cout << "请输入正确的选项!" << endl ;
cout << "请输入选项:" ;
cin >> choice ;
cin.ignore(1024,'\n');
choi (choice) ;
break;
}
}
bool check (string num)
{
for (int i = 0 ;i < num.length ( ) ;i ++)
if ( (num.c_str ( ) [i] < '0' || num.c_str ( ) [i] > '9') && (num.c_str ( ) [i] != '.') )
return false ;
return true ;
}
void creat (book* head)
{}
void display (book* head)
{
if (!head)
{
cin.ignore(1024,'\n');//-------清楚缓冲区的状态
cout << "你还没有图书,请先创建或添加图书!按回车键继续" << endl ;
cin.get ( ) ;//-----这个就是吸收回车的
choi(dis_func ( )) ;
}
else
while (head)
{
cout << "编号:" << head -> num << " 价钱:" << head -> price << endl ;
head = head -> next ;
}
cin.ignore(1024,'\n');//-------清楚缓冲区的状态
cout << "按回车键继续......" ;
cin.get ( ) ;
choi(dis_func ( )) ;
}
void insert (book* head)
{
}
void del (book *head)
{
}
int number (book *head)
{
return 1;
}
#include <iostream>
#include <string>
using namespace std ;
//定义类book
class book
{
public :
int num ;
double price ;
book* next ;
} ;
//声明全局变量
book* head = NULL ;
//声明函数
void creat (book* head) ;
void display (book* head) ;
void insert (book* head) ;
void del (book *head) ;
char dis_func ( ) ;
void choi (char choice) ;
int number (book *head) ;
bool check ( ) ;
//主函数main ( )
int main ( )
{
char choice = dis_func ( ) ;
choi (choice) ;
}
//函数定义
char dis_func ( )
{
char choice ;
system ("cls") ;
cout << "1.重建图书 2.显示图书 3.插入图书 4.删除图书 5.图书数目 q.退出" << endl ;
cout << "请输入你的选择:" ;
cin >> choice ;
return choice ;
}
void choi (char choice)
{
switch (choice)
{
case '1' :creat (head) ;
break ;
case '2' :display (head) ;
break ;
case '3' :insert (head) ;
break ;
case '4' :del (head) ;
break ;
case '5' :cout << "图书数目:" << number (head) << endl ;
choi(dis_func ( ) ) ;
break ;
case 'q' :exit (0) ;
break ;
default :cout << "请输入正确的选项!" << endl ;
cout << "请输入选项:" ;
cin >> choice ;
choi (choice) ;
}
}
bool check (string num)
{
for (int i = 0 ;i < num.length ( ) ;i ++)
if ( (num.c_str ( ) [i] < '0' || num.c_str ( ) [i] > '9') && (num.c_str ( ) [i] != '.') )
return false ;
return true ;
}
void creat (book* head)
{
}
void display (book* head)
{
if (!head)
{
cout << "你还没有图书,请先创建或添加图书!按回车键继续" << endl ;
fflush(stdin);//只需在cin()前清理缓冲区就行了
cin.get ( ) ;
choi(dis_func ( )) ;
}
else
while (head)
{
cout << "编号:" << head -> num << " 价钱:" << head -> price << endl ;
head = head -> next ;
}
cout << "按回车键继续......" ;
cin.get ( ) ;
choi(dis_func ( )) ;
}
void insert (book* head)
{
}
void del (book *head)
{
}
int number (book *head)
{
return 1;
}
char dis_func ( )
{
char choice ;
system ("cls") ;//------------------他把你的结果清屏了
cout << "1.重建图书 2.显示图书 3.插入图书 4.删除图书 5.图书数目 q.退出" << endl ;
cout << "请输入你的选择:" ;
cin >> choice;
cin.ignore(1024,'\n');//另外一种修改的方法就是在你输入的时候就清理掉 '\n'
return choice;
}
if (!head)
{
cin.ignore(1024,'\n');//-------清楚缓冲区的状态
cout << "你还没有图书,请先创建或添加图书!按回车键继续" << endl ;
cin.get ( ) ;//-----这个就是吸收回车的
//这是我一般的做法
char dis_func ( )
{
char choice ;
system ("cls") ;//------------------他把你的结果清屏了
cout << "1.重建图书 2.显示图书 3.插入图书 4.删除图书 5.图书数目 q.退出" << endl ;
cout << "请输入你的选择:" ;
cin >> choice;
return choice;
}
void display (book* head)
{
if (!head)
{
cout << "你还没有图书,请先创建或添加图书!按回车键继续" << endl ;
cin.get ( ) ;//第一个接受到实际是最初漏下去的那个回车符
cin.get(); //这个才停住
choi(dis_func ( )) ;
}