JBTALKS.CC

标题: C++请各位帮帮忙... [打印本页]

作者: JLS    时间: 2009-7-27 01:56 AM
标题: C++请各位帮帮忙...
我不知道哪里出了问题...我是新手...我一直进不去我的系统

  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
复制代码

作者: Super-Tomato    时间: 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
作者: JLS    时间: 2009-7-27 11:36 AM
原帖由 Super-Tomato 于 2009-7-27 11:19 AM 发表


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

那要怎么改呢?
作者: Super-Tomato    时间: 2009-7-27 12:24 PM
原帖由 JLS 于 2009-7-27 11:36 AM 发表

那要怎么改呢?



menu 改為 char, 之後的 case 全部把 int 改為 char, 如 case '1':
作者: JLS    时间: 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就不用改了?
作者: Super-Tomato    时间: 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 類型的意思
作者: JLS    时间: 2009-7-27 09:55 PM
标题: 回复 #6 Super-Tomato 的帖子
懒惰思考了...做了很久了...我是新手...学四个月了...找书找到要死=.=
果然不适合读这科....哈哈哈
作者: JLS    时间: 2009-7-27 10:06 PM
我明白了...谢谢你...但还是有error。。。haiz
好烦>.<
作者: Super-Tomato    时间: 2009-7-27 10:20 PM
原帖由 JLS 于 2009-7-27 10:06 PM 发表
我明白了...谢谢你...但还是有error。。。haiz
好烦>.



最好把你的错误贴出来,不然也我們也懒惰去測試
作者: JLS    时间: 2009-7-27 11:49 PM
想请问下delete code怎么写? 我不大会写delete
因我case 3
delete不到资料>.<
作者: 宅男-兜着走    时间: 2009-7-28 12:48 AM
标题: 回复 #10 JLS 的帖子
拜五交啊 == , 怎么外面也是有个一样是在 写这个 类似的 console program 的。 你们同校的哦? 加油哦
作者: Super-Tomato    时间: 2009-7-28 02:09 AM
原帖由 JLS 于 2009-7-27 11:49 PM 发表
想请问下delete code怎么写? 我不大会写delete
因我case 3
delete不到资料>.


在讀取檔案内容的时候把需要保留的暂存在另一处,讀取完毕之後再把另一处的内容储存到目前的檔案内容
作者: JLS    时间: 2009-7-28 06:15 AM
标题: 回复 #11 宅男-兜着走 的帖子
有吗?我想不同吧?...哈哈
作者: ~忆~    时间: 2009-7-30 07:24 PM
各位大大前辈!我想问一个问题!~我运行已经排好程序(VC++2008),出来的结果是DOS闪一下而已!有办法解决麻?(不要system("pause"))
作者: 宅男-兜着走    时间: 2009-7-30 07:38 PM
标题: 回复 #14 ~忆~ 的帖子
那么就没办法了 == 我的vista 也是这样, 不 system pause 的话马上会消失。
作者: ~忆~    时间: 2009-7-30 08:03 PM
标题: 回复 #15 宅男-兜着走 的帖子
哦哦!~谢谢 ~你们都几岁开始学?  学语言要精电脑,英文,数学麻?
作者: Super-Tomato    时间: 2009-7-30 08:20 PM
原帖由 ~忆~ 于 2009-7-30 07:24 PM 发表
各位大大前辈!我想问一个问题!~我运行已经排好程序(VC++2008),出来的结果是DOS闪一下而已!有办法解决麻?(不要system("pause"))



很簡單啊,就等待使用者輸入任何键再继续
呃~~~~ 不知道你們有沒有用心看一下樓主的 coding, 他已經写好了這個范例
作者: 宅男-兜着走    时间: 2009-7-31 01:44 AM
标题: 回复 #17 Super-Tomato 的帖子
不, input 资料的时候我懂会等, 但是 calculate 好结果过后马上就不见了。
作者: Super-Tomato    时间: 2009-7-31 06:00 AM
原帖由 宅男-兜着走 于 2009-7-31 01:44 AM 发表
不, input 资料的时候我懂会等, 但是 calculate 好结果过后马上就不见了。



恕小弟不才不明白您的意思,可否給於個最简单的例子?
作者: ~忆~    时间: 2009-8-1 04:49 PM
标题: 回复 #19 Super-Tomato 的帖子
大概是说,我们想要的是按close(右上角的X像cmd)才会自己关闭= =可是他是自己闪一下就不见了!欠缺美观!

如果把做好的程序放在无编程工具的电脑运行?
作者: Super-Tomato    时间: 2009-8-1 06:26 PM
原帖由 ~忆~ 于 2009-8-1 04:49 PM 发表
大概是说,我们想要的是按close(右上角的X像cmd)才会自己关闭= =可是他是自己闪一下就不见了!欠缺美观!

如果把做好的程序放在无编程工具的电脑运行?


Console 中只要在入口函数做 return 自然就會关闭了啊,这好像是基本知识,要不讓关闭只要不讓程式执行到 return 就可以了




欢迎光临 JBTALKS.CC (https://www.jbtalks.cc/) Powered by Discuz! X2.5