回覆列表
  • 1 # 小紅的甜心

    想要它變成什麼樣,自己做一下修改就是了:

    #include<iostream>

    #include<fstream>

    #include <windows.h>

    #include<string>

    #include <time.h>

    #include<cstdlib>

    #include<iomanip>

    using namespace std;

    int n=0;

    #define M cout<<

    #define N ;Sleep(80);

    #define Y N M

    #define NN cout<<"╭—————————————————————————————————————————————╮"<<endl;cout<<"∣ num ∣ name∣ age ∣ hig ∣ 語文 ∣ 數學 ∣ 英語 ∣ 平均 ∣ 總分 ∣ 評語 ∣ "<<endl;cout<<"├———-┼———-┼———┼———┼———-┼———-┼———-┼—————┼————┼———-┤"<<endl;cout<<"∣"<<setw(6)<<p1->num<<setw(3)<<"∣"<<setw(7)<<p1->name<<setw(2)<<"∣"<<setw(4)<<p1->age<<setw(4)<<"∣"<<setw(4)<<p1->hig<<setw(4)<<"∣"<<setw(5)<<p1->score[0]<<setw(4)<<"∣"<<setw(5)<<p1->score[1]<<setw(4)<<"∣"<<setw(5)<<p1->score[2]<<setw(4)<<"∣"<<setw(8)<<setprecision(3)<<p1->ave<<setw(4)<<"∣"<<setw(6)<<p1->sum<<setw(4)<<"∣"<<setw(7)<<p1->p_y<<setw(2)<<"∣"<<endl;cout<<"  ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ "<<endl;

    ////////////////////////////////////////////////////////////////////////////////////////////

    ////

    ////

    ////

    ////////////////////////////////////////////////////////////////////////////////////////////

    class ji_ke_1_class

    {

    int num;

    char name[20];

    int age;

    float hig;

    int score[3];

    float ave;

    float sum;

    char p_y[10];

    public:

    void set_date();

    void display();

    void creat();

    void print();

    void insert();

    void exchange(ji_ke_1_class *p1,ji_ke_1_class *p2);

    void sort(int j);

    void index(int q,char aa[20]);

    void del(int num);

    void save();

    void tongji();

    void load();

    class ji_ke_1_class *next;

    };

    ji_ke_1_class *head,*p1,*p2,*p;

    void ji_ke_1_class::set_date ()

    {

    cout<<"學號_姓名_年齡_身高_"<<endl;

    cin>>num>>name>>age>>hig;

    cout<<"-----分數::語文_數學_英語_"<<endl<<" ";

    for(int i=0;i<3;i++)

    cin>>score[i] ;

    }

    void ji_ke_1_class::display()

    {

    ji_ke_1_class *p;

    int i;

    for( p=head , i=0 ; i<n ; i++ , p=p->next )

    cout<<"∣"

    <<setw(6)<<p->num

    <<setw(3)<<"∣"

    <<setw(7)<<p->name

    <<setw(2)<<"∣"

    <<setw(4)<<p->age

    <<setw(4)<<"∣"

    <<setw(4)<<p->hig

    <<setw(4)<<"∣"

    <<setw(5)<<p->score[0]

    <<setw(4)<<"∣"

    <<setw(5)<<p->score[1]

    <<setw(4)<<"∣"

    <<setw(5)<<p->score[2]

    <<setw(4)<<"∣"

    <<setw(8)<<setprecision(3)<<p->ave

    <<setw(4)<<"∣"

    <<setw(6)<<p->sum

    <<setw(4)<<"∣"

    <<setw(7)<<p->p_y

    <<setw(2)<<"∣"

    <<endl;

    }

    void ji_ke_1_class::print()

    {

    ji_ke_1_class *p0=head;

    cout<<"╭—————————————————————————————————————————————╮"<<endl;

    cout<<"∣ num ∣ name∣ age ∣ hig ∣ 語文 ∣ 數學 ∣ 英語 ∣ 平均 ∣ 總分 ∣ 評語 ∣ "<<endl;

    cout<<"├———-┼———-┼———┼———┼———-┼———-┼———-┼—————┼————┼———-┤"<<endl;

    p0->display();

    cout<<"  ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ "<<endl;

    }

    void ji_ke_1_class::creat()

    {

    int m=0;

    float total=0;

    head=p2=p1=new ji_ke_1_class;

    p1->set_date();

    while(p1->num!=0)

    {

    n=n+1;

    if(n==1)

    head=p1;

    else

    p2->next=p1;

    p2=p1;

    p1=new ji_ke_1_class;

    p1->set_date ();

    }

    p2->next=0;

    ji_ke_1_class *p=new ji_ke_1_class;

    for(p=head ; m<n ; p=p->next )

    {

    total=total+p->score[0]+p->score[1]+p->score[2];

    p->sum=total;

    p->ave=total/3;

    cout<<p->sum<<"--------__"<<p->ave<<endl;

    if(p->ave>85) strcpy( p->p_y , "優秀" );

    else if(p->ave>75) strcpy( p->p_y , "中等" );

    else if(p->ave>60) strcpy( p->p_y , "及格" );

    else strcpy( p->p_y , "不及格" );

    total=0;

    m+=1;

    }

    }

    template<typename T1>

    void exchang1(T1 &a,T1 &b)

    {

    int t;

    t=a;

    a=b;

    b=t;

    }

    template<typename T2>

    void exchang2(T2 &a,T2 &b)

    {

    float t;

    t=a;

    a=b;

    b=t;

    }

    void ji_ke_1_class::exchange(ji_ke_1_class *p1,ji_ke_1_class *p2)

    {

    char t2[30],t1[10];

    exchang1(p1->num,p2->num);

    exchang1(p1->score[1],p2->score[1]);

    exchang1(p1->score[0],p2->score[0]);

    exchang1(p1->score[2],p2->score[2]);

    exchang2(p1->hig,p2->hig);

    exchang2(p1->ave,p2->ave);

    exchang2(p1->sum,p2->sum);

    strcpy(t2,p1->name);

    strcpy(p1->name,p2->name);

    strcpy(p2->name,t2);

    strcpy(t1,p1->p_y );

    strcpy(p1->p_y ,p2->p_y );

    strcpy(p2->p_y ,t1);

    }

    void ji_ke_1_class::sort(int j)

    {

    ji_ke_1_class *p1,*p2;

    int m,t;

    cout<<endl;

    for(p1=head , m=0 ; m<n-1 ; m++ , p1=p1->next)

    for(p2=p1->next,t=m+1 ; t<n ; t++ , p2=p2->next)

    {

    if( (p1->num) > (p2->num) && j==1 ) exchange(p1,p2);

    if( (p1->sum) < (p2->sum) && j==2 ) exchange(p1,p2);

    }

    print();

    cout<<endl;

    }

    void ji_ke_1_class::del(int num)

    {

    ji_ke_1_class *p1,*p2;

    if(head==0)

    {

    cout<<"\nlist null!\n";

    goto end1;

    }

    p1=head;

    while(num!=p1->num && p1->next!=0)

    {

    p2=p1;

    p1=p1->next;

    }

    if(num==p1->num)

    {

    if(p1==head) head=p1->next;

    else p2->next=p1->next;

    cout<<"\n"<<"恭喜你--deleted the:"<<num<<endl<<endl;

    n=n-1;

    }

    else cout<<num<<"抱歉--好像沒有這個數吧!!\n"<<"\n\n";

    end1: ;

    }

    void ji_ke_1_class::insert()

    {

    float total;

    ji_ke_1_class *pt=new ji_ke_1_class;

    ji_ke_1_class *p0,*p1,*p2;

    pt=new ji_ke_1_class;

    pt->set_date();

    total=0;

    int i;

    for(i=0;i<3;i++)

    total+=pt->score[i];

    pt->sum=total;

    pt->ave=total/3;

    if(pt->ave>85) strcpy( pt->p_y , "優秀" );

    else if(pt->ave>75) strcpy( pt->p_y , "中等" );

    else if(pt->ave>60) strcpy( pt->p_y , "及格" );

    else strcpy( pt->p_y , "不及格" );

    p1=head;

    p0=pt;

    if(head==0)

    {

    head=p0;

    p0->next=0;

    }

    else

    {

    while( (p0->num>p1->num)&&(p1->next!=0))

    {

    p2=p1;

    p1=p1->next;

    }

    if(p0->num<=p1->num)

    {

    if(head==p1) head=p0;

    else p2->next=p0;

    p0->next=p1;

    }

    else

    {

    p1->next=p0;

    p0->next=0;

    }

    }

    n=n+1;

    }

    void ji_ke_1_class::index(int q,char aa[20])

    {

    ji_ke_1_class *p1=head;

    int m=0,j=0;

    int len,flag=1;

    int a[4];

    for( m=0 ; m<n ; p1=p1->next , m++ )

    {

    a[0]=0;a[1]=0;a[2]=0;a[3]=0;

    flag=1;

    a[0]=(int)( (p1->num)/1000 ); a[1]=(int)( (p1->num-a[0]*1000 )/100 );

    a[2]=(int)( (p1->num-a[1]*100-a[0]*1000 )/10 ); a[3]=(int)( p1->num-a[1]*100-a[0]*1000-a[2]*10 );

    for(int i=19 ; i>=0 ; i--)

    {

    if(aa[i]!=0)

    len=i+1;

    }

    int m[4],k=0,y=0,x=0,d=0;

    for(k=0;k<4;k++)

    {

    d=0;

    y=(int)aa[k];

    for(x=48;x<=57;x++)

    {

    d++;

    if(x==y) m[k]=(d-1);

    }

    }

    for(j=0 ; j<4 ; j++ )

    {

    if( a[j]!=m[j] )

    flag=0;

    }

    if( flag==1 && q==1 )

    {

    NN

    break;

    }

    if( p1->name[0]==aa[0] && p1->name[1]==aa[1] && p1->name[2]==aa[2] && q==2 )

    {

    NN

    break;

    }

    }

    if( m==n ) cout<<"no the student"<<endl;

    }

    int x[20];

    string filename;

    void ji_ke_1_class::save()

    {

    int d,d1=0;

    int ii;

    cout<<endl<<"請輸入儲存路徑(建議存入當前檔案中的data_save中)(例 ---絕對路徑:C:\\\\檔名\\\\檔名\\\\資料名.dat \n "

    <<" ---相對路徑:save\\\\資料名.dat; )"

    <<endl

    <<"路徑為:";

    string cc;

    cin>>cc;

    cout<<" ╭——————————————╮"<<endl<<"正在儲存 ";

    for(ii=0;ii<15;ii++)

    {

    cout<<"\20";

    Sleep(15);

    }

    ifstream file1("程式必用1.dat",ios::binary);

    file1.read( (char *)&d , sizeof(d) );

    d1=(int)d+1;

    file1.close();

    string filename0,name_file;

    filename0=cc;

    name_file=filename0.c_str();

    ofstream file2("程式必用1.dat",ios::binary);

    file2.write( (char *)&d1 , sizeof(d1) );

    file2.close();

    ofstream file3("程式必用2.dat", ios::app|ios::out );

    file3<<name_file.c_str ()<<" ";

    file3.close();

    ofstream outfile(cc.c_str(),ios::binary);

    if(!outfile)

    {

    cerr<<"!!!!!"<<endl;

    abort();

    }

    outfile.write( (char *)&n , sizeof(n) );

    ji_ke_1_class *p=head;

    for(int i=0;i<n;i++,p=p->next)

    outfile.write( (char *)p,sizeof(ji_ke_1_class));

    outfile.close();

    for(ii=0;ii<15;ii++)

    {

    cout<<"\20";

    Sleep(15);

    }

    cout<<endl<<endl;

    cout<<"-----已成功儲存!!!!!!"<<endl<<endl;

    }

    void ji_ke_1_class::load()

    {

    int h1,h2;

    string qq,name[20],name0[20];

    ifstream file("程式必用1.dat",ios::binary);

    if(!file)

    {

    cerr<<"open error!!"<<endl;

    abort();

    }

    file.read( (char *)&h1, sizeof(h1) );

    h2=int(h1);

    cout<<"共有以下 "<<h2<<" 個檔案"<<endl;

    ifstream file0("程式必用2.dat",ios::in);

    if(!file0)

    {

    cerr<<"open error!!"<<endl;

    abort();

    }

    for(int e=0;e<h2;e++)

    {

    if(e%2==0) cout<<endl;

    file0>>name[e];

    name0[e]=name[e];

    cout<<"第"<<e+1<<"個檔案:"<<setw(16)<<(string)name0[e]<<" ; ";

    }

    file0.close();

    cout<<endl;

    loop3:

    cout<<endl<<"請輸入路徑(例 ---絕對路徑:C:\\\\檔名\\\\檔名\\\\資料名.dat ---相對路徑:save\\\\資料名.dat;)"<<endl ;

    cout<<"路徑為:";

    string ccc;

    cin>>ccc;

    cout<<" ╭——————————————╮"<<endl<<"正在讀取 ";

    int ii;

    for(ii=0;ii<15;ii++)

    {

    cout<<"\20";

    Sleep(15);

    }

    ifstream infile(ccc.c_str(),ios::binary);

    int c;

    ji_ke_1_class t[60],*pp[60];

    if(!infile)

    {

    cout<<endl<<"無此檔案; 1---重輸 ; other---放棄";

    cin>>c;

    if(c==1) goto loop3;

    else goto loop4;

    }

    int nn,nnn;

    int i;

    infile.read( (char *)&nn , sizeof(nn) );

    nnn=(int)nn;

    n=nnn;

    infile.read( (char *)&t[0] , sizeof(ji_ke_1_class) );

    head=(ji_ke_1_class *)&t[0];

    for(i=1; i<nnn; i++)

    {

    infile.read( (char *)&t[i] , sizeof(ji_ke_1_class) );

    pp[i]=(ji_ke_1_class *)&t[i];

    if(i==1)

    {

    head->next=pp[1];

    }

    if(i!=1)

    {

    pp[i-1]->next=pp[i];

    }

    }

    infile.close();

    for(ii=0;ii<15;ii++)

    {

    cout<<"\20";

    Sleep(15);

    }

    cout<<endl;

    cout<<endl<<"————————恭喜!!!成功裝載,資料檔案以可以使用"<<endl<<endl;

    loop4:;

    }

    void ji_ke_1_class::tongji()

    {

    ji_ke_1_class *pm=head;

    int m,by=0,bz=0,bc=0,bj=0;

    for(pm=head , m=0 ; m<n ; m++ , pm=pm->next)

    {

    if( pm->ave >= 85 ) by++;

    if( pm->ave < 85 && pm->ave >=75 ) bz++;

    if( pm->ave >=60 && pm->ave < 75 ) bj++;

    if( pm->ave < 60 ) bc++;

    }

    cout<<endl

    <<"總計 "<<n<<" 人:"<<endl

    <<" 優秀生人數:"<<setw(5)<<by<<setw(12)<<"優秀率為:"<<setw(6)<<setprecision(5)<<(double)by/n<<endl

    <<" 中等生人數:"<<setw(5)<<bz<<setw(12)<<"中等率為:"<<setw(6)<<setprecision(5)<<(double)bz/n<<endl

    <<" 及格生(60-75)人數:"<<setw(5)<<bj<<setw(12)<<"及格率為:"<<setw(6)<<setprecision(5)<<(double)bj/n<<endl

    <<" 不及格人數為:"<<setw(5)<<bc<<setw(12)<<"不及格率為:"<<setw(6)<<setprecision(5)<<(double)bc/n<<endl<<endl;

    }

    void bz()

    {

    system("cls");

    M"歡"Y"迎"Y"使"Y"用"Y"本"Y"程"Y"序"Y"-"Y"-"Y"-"Y"-"Y"-"Y" 使"Y"用"Y"說"Y"明"Y":"N;cout<<endl<<endl;

    M"一"Y""Y"、"Y"建"Y"立"Y"自"Y"己"Y"的"Y"數"Y"據"Y"("Y"建"Y"議"Y"馬"Y"上"Y"存"Y"儲"Y"!"Y"!"Y")"Y"按"Y"提"Y"示"Y"操"Y"作"Y"即"Y"可"Y";"Y"呵"Y"呵"N;cout<<endl<<endl;

    M"二"Y""Y"、"Y"注"Y"意"Y"事"Y"項"Y":"Y" 對"Y"鏈"Y"表"Y"("Y"數"Y"據"Y")"Y"若"Y"超"Y"過"Y"6"Y"0"Y"個"Y","Y"則"Y"請"Y"聯"Y"系"Y""Y""Y"呂"Y""Y""Y"威"Y""Y""Y"___"Y"qq"Y":"Y"921963406"Y","Y"可"Y"免"Y"費"Y"贈"Y"送"Y"所"Y"需"Y"程"Y"序"N;cout<<endl<<endl;

    M"三"Y""Y"、"Y"建"Y"鏈"Y"表"Y"的"Y"最"Y"後"Y"使"Y"全"Y"為"Y"0"Y","Y"建"Y"表"Y"結"Y"束"N;cout<<endl<<endl;

    M"四"Y""Y"、"Y"因"Y"技"Y"術"Y"有"Y"限"Y","Y"清"Y"屏"Y"函"Y"數"Y"造"Y"成"Y"head"Y"丟"Y"失"Y";"Y"慎"Y"用"Y"!"Y"!"N;cout<<endl<<endl<<" ";

    M"制"Y"作"Y"人"Y":"Y""Y""Y""Y""Y"呂"Y""Y""Y""Y""Y"威"Y""Y""Y""Y""N;cout<<endl<<endl;

    }

    ////////////////////////////////////////////////////////////////////////////////////////////

    ////

    ////

    ////////////////////////////////////////////////////////////////////////////////////////////

    void mult()

    {tm * tp;

    time_t t;

    cout<<"____________________________________________________________________________________________________\n";

    cout<<" ╭——————————————╮\n"

    <<" ";

    t=time(NULL);

    tp=localtime(&t);

    cout<<tp->tm_mon+1<<"-"<<tp->tm_mday<<"-"<<tp->tm_year+1900<<" ";

    cout<<tp->tm_hour<<":"<<tp->tm_min<<":"<<tp->tm_sec;

    cout<<" ∣ 選單 ∣ \n"

    <<" ∣____________________________∣\n"

    <<" ∣ 0---建立資料 ∣\n"

    <<" ∣ ∣\n"

    <<" ∣ 1---按學號排序 ∣\n"

    <<" ∣ ∣\n"

    <<" ∣ 2---按分數排序 ∣\n"

    <<" ∣ ∣\n"

    <<" ∣ ∣\n"

    <<" ∣ 4---插入一學生資訊 ∣\n"

    <<" ∣ ∣\n"

    <<" ∣ 5---檢索一學生 ∣\n"

    <<" ∣ ∣\n"

    <<" ∣ 6---統計資料 ∣\n"

    <<" ∣ ∣\n"

    <<" ∣ 7---儲存 ∣\n"

    <<" ∣ ∣\n"

    <<" ∣ 8---開啟 ∣\n"

    <<" ∣ ∣\n"

    <<" ∣ 9---清屏 ∣\n"

    <<" ∣ ∣\n"

    <<" ∣ 10--幫助(建議先看) ∣\n"

    <<" ∣ other---quit ∣\n"

    <<" ∣ ∣\n"

    <<"  ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄\n";

    }

    void select()

    {

    int fl=0,a,num2;

    ji_ke_1_class aa;

    loop:

    cout<<"What can I do for you ? ? ?(輸入命令---數字) :";

    cin>>a;

    switch(a)

    {

    case 0 :

    {

    cout<<"輸入資料\n";

    aa.creat();

    aa.print();

    goto loop;

    }

    case 1 :

    {

    aa.sort(1);

    goto loop;

    }

    case 2 :

    {

    aa.sort(2);

    goto loop;

    }

    case 3 :

    {

    cout<<"num========";

    cin>>num2;

    aa.del(num2);

    goto loop;

    }

    case 4 :

    {

    aa.insert();

    goto loop;

    }

    case 5 :

    {

    char xx[20]={0};

    cout<<"輸入要查詢的學生的學號 或 姓名:";

    cin>>xx;

    if( xx[0]>=48 && xx[0]<=57 )

    aa.index(1,xx);

    else

    aa.index(2,xx);

    goto loop;

    }

    case 6 :

    {

    aa.tongji();

    goto loop;

    }

    case 7 :

    {

    aa.save();

    fl=1;

    goto loop;

    }

    case 8 :

    {

    aa.load();

    goto loop;

    }

    case 9 :

    {

    ji_ke_1_class *nn=new ji_ke_1_class;

    head=nn;

    system("cls");//清屏造成head丟失-------------------------------------------------------??????????????????

    nn=head;

    mult();

    goto loop;

    }

    case 10 :

    {

    bz();

    mult();

    goto loop;

    }

    default :

    {

    if(fl=0)

    {

    char f;

    cout<<"你想要儲存嗎?y/N";

    cin>>f;

    if(f=="y"||f=="y")

    {

    aa.save();

    fl=1;

    goto loop;

    }

    else goto end;

    }

    else goto end;

    }

    }

    end:;

    }

    void main()

    {

    int q2=0;

    ifstream file0("程式必用1.dat",ios::binary);

    if(!file0)

    {

    file0.close();

    ofstream file1("程式必用1.dat",ios::binary);

    file1.write( (char *)&q2 , sizeof(q2) );

    file1.close();

    goto loop5;

    }

    file0.close();

    loop5:

    mult();

    select();

    }

  • 中秋節和大豐收的關聯?
  • KYMCQTM註冊過商標嗎?還有哪些分類可以註冊?