ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 성적표 구현(무배열)
    카테고리 없음 2013. 2. 20. 01:46
    반응형

    배열을 사용하지않고 구현함으로써 설계와 일치 하지않는다.

    #include<iostream>
    #include <windows.h>
    #include<iomanip>
    using namespace std;
    int main(void)
    {
    cout << "\t▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣" << endl;
    cout << "\t▣┌──────────────────┐▣" << endl;
    cout << "\t▣│             성  적  표             │▣" << endl;
    cout << "\t▣└──────────────────┘▣" << endl;
    cout << "\t▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣" <<endl<<endl;
    /-학생정보: -->학번,국어,수학,영어,총점,평점<-- 초기화*-
    //첫번째 학생
    int sid_1=0;//학번
    double kor_1=0,eng_1=0,math_1=0,total_1=0,aver_1=0;//과목,총점,평균
    //두번째 학생
    int sid_2=0;//학번
    double kor_2=0,eng_2=0,math_2=0,total_2=0,aver_2=0;//과목,총점,평균
    //세번째 학생
    int sid_3=0;//학번
    double kor_3=0,eng_3=0,math_3=0,total_3=0,aver_3=0;//과목,총점,평균
    cout<<"첫번째 학생 입력"<<endl;
    cout<<"학번 :";cin>>sid_1;
    cout<<"국어 :";cin>>kor_1;
    while (kor_1>100)
    {
    cout<<"성적은 100이하로 입력하셔야 합니다."<<endl;
    cout<<"국어 :";cin>>kor_1;
    }
    cout<<"수학 :";cin>>math_1;
    while (math_1>100)
    {
    cout<<"성적은 100이하로 입력하셔야 합니다."<<endl;
    cout<<"수학 :";cin>>math_1;
    }
    cout<<"영어 :";cin>>eng_1;
    while (eng_1>100)
    {
    cout<<"성적은 100이하로 입력하셔야 합니다."<<endl;
    cout<<"영어 :";cin>>eng_1;
    }
    total_1=kor_1+math_1+eng_1;
    aver_1=total_1/3;
    system("cls");
    cout << "\t▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣" << endl;
    cout << "\t▣┌──────────────────┐▣" << endl;
    cout << "\t▣│             성  적  표             │▣" << endl;
    cout << "\t▣└──────────────────┘▣" << endl;
    cout << "\t▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣" <<endl<<endl;
    cout<<"두번째 학생 입력"<<endl;
    cout<<"학번 :";cin>>sid_2;
    while (sid_2==sid_1)
    {
    cout<<"학번이 존재 합니다."<<endl;
    cout<<"학번 :";cin>>sid_2;
    }
    cout<<"국어 :";cin>>kor_2;
    while (kor_2>100)
    {
    cout<<"성적은 100이하로 입력하셔야 합니다."<<endl;
    cout<<"국어 :";cin>>kor_2;
    }
    cout<<"수학 :";cin>>math_2;
    while (math_2>100)
    {
    cout<<"성적은 100이하로 입력하셔야 합니다."<<endl;
    cout<<"수학 :";cin>>math_2;
    }
    cout<<"영어 :";cin>>eng_2;
    while (eng_2>100)
    {
    cout<<"성적은 100이하로 입력하셔야 합니다."<<endl;
    cout<<"영어 :";cin>>eng_2;
    }
    total_2=kor_2+math_2+eng_2;
    aver_2=total_2/3;
    system("cls");
    cout << "\t▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣" << endl;
    cout << "\t▣┌──────────────────┐▣" << endl;
    cout << "\t▣│             성  적  표             │▣" << endl;
    cout << "\t▣└──────────────────┘▣" << endl;
    cout << "\t▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣" <<endl<<endl;
    cout<<"세번째 학생 입력"<<endl;
    cout<<"학번 :";cin>>sid_3;
    while(sid_3==sid_1 || sid_3==sid_2)
    {
    cout<<"학번이 존재 합니다."<<endl;
    cout<<"학번 :";cin>>sid_3;
    }
    cout<<"국어 :";cin>>kor_3;
    while (kor_3>100)
    {
    cout<<"성적은 100이하로 입력하셔야 합니다."<<endl;
    cout<<"국어 :";cin>>kor_3;
    }
    cout<<"수학 :";cin>>math_3;
    while (math_3>100)
    {
    cout<<"성적은 100이하로 입력하셔야 합니다."<<endl;
    cout<<"수학 :";cin>>math_3;
    }
    cout<<"영어 :";cin>>eng_3;
    while (eng_3>100)
    {
    cout<<"성적은 100이하로 입력하셔야 합니다."<<endl;
    cout<<"영어 :";cin>>eng_3;
    }
    total_3=kor_3+math_3+eng_3;
    aver_3=total_3/3;
    system("cls");
    cout << "\t▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣" << endl;
    cout << "\t▣┌──────────────────┐▣" << endl;
    cout << "\t▣│             성  적  표             │▣" << endl;
    cout << "\t▣└──────────────────┘▣" << endl;
    cout << "\t▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣" <<endl<<endl;
    //출력시 공간을 맞추기 위하여 setw 함수를 사용
    cout<<"\t 학번    국어    수학    영어    총점        평점    \n";
    cout<<endl;
    cout<<"\t"<<setw(4)<<sid_1<<setw(7)<<kor_1<<setw(8)<<math_1<<setw(8)<<eng_1<<setw(8)<<total_1<<setw(13)<<aver_1<<"\n";
    cout<<"\t"<<setw(4)<<sid_2<<setw(7)<<kor_2<<setw(8)<<math_2<<setw(8)<<eng_2<<setw(8)<<total_2<<setw(13)<<aver_2<<"\n";
    cout<<"\t"<<setw(4)<<sid_3<<setw(7)<<kor_3<<setw(8)<<math_3<<setw(8)<<eng_3<<setw(8)<<total_3<<setw(13)<<aver_3<<"\n";
    cout<<endl<<endl;
    int number;
    cout<<"\t삭제 하시려는 학번입력 :";cin>>number;
    if (number==sid_1)
    {
    cout<<"\t"<<setw(4)<<sid_1<<"학번의 정보가 삭제 되었습니다."<<endl<<endl;
    sid_1=0;
    }
    else if (number==sid_2)
    {
    cout<<"\t"<<setw(4)<<sid_2<<"학번의 정보가 삭제 되었습니다."<<endl<<endl;
    sid_2=0;
    }
    else if (number==sid_3)
    {
    cout<<"\t"<<setw(4)<<sid_3<<"학번의 정보가 삭제 되었습니다."<<endl<<endl;
    sid_3=0;
    }
    else
    {
    cout<<"삭제하시려는 학번이 존재 하지않습니다."<<endl;
    }
    system("cls");
    cout << "\t▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣" << endl;
    cout << "\t▣┌──────────────────┐▣" << endl;
    cout << "\t▣│             성  적  표             │▣" << endl;
    cout << "\t▣└──────────────────┘▣" << endl;
    cout << "\t▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣" <<endl<<endl;
    if (sid_1==0)
    {
    cout<<"\t 학번    국어    수학    영어    총점        평점    \n";
    cout<<endl;
    cout<<"\t"<<setw(4)<<sid_2<<setw(7)<<kor_2<<setw(8)<<math_2<<setw(8)<<eng_2<<setw(8)<<total_2<<setw(13)<<aver_2<<"\n";
    cout<<"\t"<<setw(4)<<sid_3<<setw(7)<<kor_3<<setw(8)<<math_3<<setw(8)<<eng_3<<setw(8)<<total_3<<setw(13)<<aver_3<<"\n";
    cout<<endl<<endl;
    }
    else if (sid_2==0)
    {
    cout<<"\t 학번    국어    수학    영어    총점        평점    \n";
    cout<<endl;
    cout<<"\t"<<setw(4)<<sid_1<<setw(7)<<kor_1<<setw(8)<<math_1<<setw(8)<<eng_1<<setw(8)<<total_1<<setw(13)<<aver_1<<"\n";
    cout<<"\t"<<setw(4)<<sid_3<<setw(7)<<kor_3<<setw(8)<<math_3<<setw(8)<<eng_3<<setw(8)<<total_3<<setw(13)<<aver_3<<"\n";
    cout<<endl<<endl;
    }
    else if (sid_3==0)
    {
    cout<<"\t 학번    국어    수학    영어    총점        평점    \n";
    cout<<endl;
    cout<<"\t"<<setw(4)<<sid_1<<setw(7)<<kor_1<<setw(8)<<math_1<<setw(8)<<eng_1<<setw(8)<<total_1<<setw(13)<<aver_1<<"\n";
    cout<<"\t"<<setw(4)<<sid_2<<setw(7)<<kor_2<<setw(8)<<math_2<<setw(8)<<eng_2<<setw(8)<<total_2<<setw(13)<<aver_2<<"\n";
    cout<<endl<<endl;
    }
    return 0;
    }
    -- 노가다의 현장---

    반응형
Designed by Tistory.