Facebook Sharer
选择您要替换的背景颜色:
【农历新年】背景图片:
个性化设定
 注册  找回密码
查看: 2759|回复: 20
打印 上一主题 下一主题

C++请各位帮帮忙...

[复制链接]

7

主题

0

好友

827

积分

青铜长老

Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7

跳转到指定楼层
1#
发表于 2009-7-27 01:56 AM |只看该作者 |倒序浏览
我不知道哪里出了问题...我是新手...我一直进不去我的系统

  1. #include<iostream>
  2. #include<iomanip>
  3. #include<fstream>
  4. #include<cstdlib>           //declaration
  5. #include<conio.h>
  6. #include<string>
  7. using namespace std;

  8. int main()
  9. {
  10.                                                        
  11.         int StudentAge;
  12.         int menu;
  13.         int choice;
  14.         int number;
  15.         string StudentIdNo, StudentCourse, StudentAddress;
  16.         char StudentName[25];
  17.         char StudentGender[1];
  18.         char StudentIcNo[15];
  19.        
  20.                                                                 //Display main menu
  21.         cout<<"\n\n\n\n\n";
  22.         cout<<"           =.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.="<<endl;
  23.         cout<<"           =               !!COURSE REGISTRATION SYSTEM!!                ="<<endl;
  24.         cout<<"           =                   !!WELCOME TO METRO COLLEGE!!                    ="<<endl;
  25.         cout<<"           =                         \t\t\t\tDesign by Shirley Ng                      ="<<endl;
  26.         cout<<"           =.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.="<<endl;
  27.         cout<<"\n\n\n\n\n";
  28.     cout<<"                         ";

  29. while (true)
  30.         {
  31.         do
  32.         {
  33.                
  34.         cout<<"  Please enter the follwing options:\n";     //Get selection
  35.         cout<<"  1.ADD A NEW STUDENT RECORD\n";      
  36.         cout<<"  2.SEARCH STUDENT RECORD\n";
  37.         cout<<"         3.DELETE STUDENT RECORD\n";
  38.         cout<<"  4.QUIT\n";
  39.         cout<<"Enter choice(1-4):";
  40.        
  41.         menu = _getch();
  42.         }
  43.         while(false);
  44.        
  45.                 system("cls");
  46.                 switch(menu){
  47.                 case 1:            //Create new student account
  48.         cout<<" =.=.=.=.=.=.=.=.=.=.=.=.=.=.=\tNew Student Profile=.=.=.=.=.=.=.=.=.=.="<<endl;  


  49.         {
  50.                 //create new file
  51.                 ofstream output("student file.txt");
  52.                 cout<<"Student Name:\t";
  53.                  gets(StudentName);

  54.         cout<<"Student ID:\t";
  55.         cin>>StudentIdNo;
  56.         cout<<"Gender:\t";
  57.         cin>>StudentGender;
  58.         cout<<"IC No:\t";
  59.         cin>>StudentIcNo;
  60.         cout<<"Age:\t";
  61.         cin>>StudentAge;
  62.         cout<<"Student Course:\t";
  63.         cin>>StudentCourse;

  64.         output<<" New Student Profile\t"<<endl<<"Name:\t"<<StudentName<<endl;
  65.         output<<"ID:\t"<<StudentIdNo<<endl<<"Gender:\t"<<StudentGender<<endl;
  66.         output<<"Age:\t"<<StudentAge<<endl<<"IC no:\t"<<StudentIcNo<<endl;
  67.         output<<"Course:\t"<<StudentCourse<<endl<<endl;

  68.         if(StudentIdNo==StudentIdNo)
  69. {                           //when a ID aldready contains information can't using it
  70.         cerr<<"Student ID:"<<StudentIdNo<<"already contains information."<<endl;

  71. }
  72.         cout<<"\n\nStudent Record has been save to file"<<endl<<endl;       
  73.         system("pause");
  74.        
  75.         cout<<"Do you want to go back menu?\n";    //return to menu
  76.         cout<<"1. Yes"<<endl;
  77.         cout<<"2  No"<<endl;
  78.         cin>>number;
  79.        
  80.                   if (number==1)
  81.                          return main();
  82.         else
  83.                 cout<<" Thank you for register"<<endl;
  84.                 cout<<"Have A Nice Day"<<endl;
  85.         }        break;

  86.                 case 2:
  87.                         cout<<" =.=.=.=.=.=.=.=.Search Student Record=.=.=.=.=.=.=.=.=.=.=.="<<endl;

  88. //Search student record when keyin ID number
  89.                         cout<<endl;
  90.                         cout<<"Please Enter Studend ID:"<<endl;
  91.                         cin>>StudentIdNo;
  92.                         cin.ignore();
  93.                         {
  94.                         ifstream input ("student file.txt");                        //read the information
  95.                         while(!input.eof())
  96.                         {
  97.                                 input>>StudentIdNo;
  98.                                 cout<<StudentIdNo<<endl;
  99.                         }
  100.                         input.close();
  101.                         system("pause");
  102.                        
  103.         cout<<"Do you want to go back menu?\n";
  104.         cout<<"1. Yes"<<endl;
  105.         cout<<"2  No"<<endl;
  106.         cin>>number;
  107.        
  108.            if (number==1)
  109.                return main();
  110.         else
  111.                 cout<<" Thank you for register"<<endl;
  112.                 cout<<"Have A Nice Day"<<endl;
  113.                         }break;

  114.                 case 3:                                                //Delete student account

  115.                         cout<<" Please Enter Student ID:"<<endl;       
  116.                         cin.ignore();
  117.                         cout<<StudentIdNo<<endl;
  118.                         {
  119.                                 ifstream input;
  120.                                 input.open("student file.txt");
  121.                                 while(!input.eof())
  122.                                 {
  123.                                         input>>StudentIdNo;
  124.                                         cout<<StudentIdNo<<endl;
  125.                                 }
  126.                                         system ("pause");

  127.                                         cout<<"Are you sure want to delete?\n";
  128.                                         cout<<" 1. Yes"<<endl;
  129.                                         cout<<" 2. No"<<endl;
  130.                                         cin>>number;
  131.                                
  132.                                if(remove("student file.txt")==1)
  133.                                         {
  134.                                         cout<<"Data have been delele";
  135.                                         }
  136.                                         return 3;
  137.                                        
  138.                                         if(number==2)
  139.                                                 return 4;
  140.                                        input.close();
  141.                         }break;
  142.                                        
  143.                 case 4:{                                                        //Quit the program
  144.                                 cout<<"\n\n\n";
  145.                                                      
  146.                    cout<<"=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.= ";
  147.                    cout<<"     \t                       THANK YOU FOR REGISTER           ";
  148.                    cout<<"                                     METRO COLLEGE!!                      ";
  149.                    cout<<"                                          HAVE A NICE DAY!!                   ";
  150.                    cout<<"=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=. ";
  151.                
  152.                  menu=_getch();
  153.                         while(menu==4);
  154.                                                 return 0;
  155.                                 }break;

  156.                 default:                                                                       
  157.                         cout<<"Please enter again"<<endl;
  158.                         {
  159.                         while(menu>5);
  160.                         cout<<endl;
  161.                         return main ();
  162.                         }
  163.                                 }
  164.                                 }
  165. }
  166. //end of program
复制代码




收藏收藏0

7

主题

1

好友

5108

积分

一流名嘴

Rank: 12Rank: 12Rank: 12

2#
发表于 2009-7-27 11:19 AM |只看该作者
原帖由 JLS 于 2009-7-27 01:56 AM 发表
我不知道哪里出了问题...我是新手...我一直进不去我的系统

#include
#include
#include
#include           //declaration
#include
#include
using namespace std;

int main()
{
                                                       
        int  ...


_getch() 所回傳的是 char 類型而不是 int


回复

使用道具 举报

7

主题

0

好友

827

积分

青铜长老

Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7

3#
发表于 2009-7-27 11:36 AM |只看该作者
原帖由 Super-Tomato 于 2009-7-27 11:19 AM 发表


_getch() 所回傳的是 char 類型而不是 int

那要怎么改呢?


回复

使用道具 举报

7

主题

1

好友

5108

积分

一流名嘴

Rank: 12Rank: 12Rank: 12

4#
发表于 2009-7-27 12:24 PM |只看该作者
原帖由 JLS 于 2009-7-27 11:36 AM 发表

那要怎么改呢?



menu 改為 char, 之後的 case 全部把 int 改為 char, 如 case '1':


回复

使用道具 举报

7

主题

0

好友

827

积分

青铜长老

Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7

5#
发表于 2009-7-27 08:38 PM |只看该作者
原帖由 Super-Tomato 于 2009-7-27 12:24 PM 发表



menu 改為 char, 之後的 case 全部把 int 改為 char, 如 case '1':


  1. int StudentAge;
  2.         int menu;
  3.         int choice;

  4.   [color=Red] menu[/color] = _getch();
复制代码

就是上面那menu改成char?
int menu就不用改了?


回复

使用道具 举报

7

主题

1

好友

5108

积分

一流名嘴

Rank: 12Rank: 12Rank: 12

6#
发表于 2009-7-27 09:25 PM |只看该作者
原帖由 JLS 于 2009-7-27 08:38 PM 发表



int StudentAge;
        int menu;
        int choice;

   menu = _getch();

就是上面那menu改成char?
int menu就不用改了?



你能夠写出这些,應該很容易明白把 menu 改成 char 類型的意思


回复

使用道具 举报

7

主题

0

好友

827

积分

青铜长老

Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7

7#
发表于 2009-7-27 09:55 PM |只看该作者

回复 #6 Super-Tomato 的帖子

懒惰思考了...做了很久了...我是新手...学四个月了...找书找到要死=.=
果然不适合读这科....哈哈哈


回复

使用道具 举报

7

主题

0

好友

827

积分

青铜长老

Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7

8#
发表于 2009-7-27 10:06 PM |只看该作者
我明白了...谢谢你...但还是有error。。。haiz
好烦>.<


回复

使用道具 举报

7

主题

1

好友

5108

积分

一流名嘴

Rank: 12Rank: 12Rank: 12

9#
发表于 2009-7-27 10:20 PM |只看该作者
原帖由 JLS 于 2009-7-27 10:06 PM 发表
我明白了...谢谢你...但还是有error。。。haiz
好烦>.



最好把你的错误贴出来,不然也我們也懒惰去測試


回复

使用道具 举报

7

主题

0

好友

827

积分

青铜长老

Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7

10#
发表于 2009-7-27 11:49 PM |只看该作者
想请问下delete code怎么写? 我不大会写delete
因我case 3
delete不到资料>.<


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

JBTALKS.CC |联系我们 |隐私政策 |Share

GMT+8, 2024-10-25 09:15 PM , Processed in 0.108602 second(s), 27 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

Ultra High-performance Dedicated Server powered by iCore Technology Sdn. Bhd.
Domain Registration | Web Hosting | Email Hosting | Forum Hosting | ECShop Hosting | Dedicated Server | Colocation Services
本论坛言论纯属发表者个人意见,与本论坛立场无关
Copyright © 2003-2012 JBTALKS.CC All Rights Reserved
合作联盟网站:
JBTALKS 马来西亚中文论坛 | JBTALKS我的空间 | ICORE TECHNOLOGY SDN. BHD.
回顶部