(adsbygoogle = window.adsbygoogle || []).push({ google_ad_client: "ca-pub-8242763509535969", enable_page_level_ads: true }); [C++] 성적관리-동적할당 :: 깜냥깜냥
몇 명을 받는지에 대한 동적할당입니다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include<iostream>
#include<cstring>
 
#pragma warning(disable:4996)
using namespace std;
 
class Student{
private:
    char name[10];/////////////세 사람 성적 구하기
    int score[4];//국,영,수,총
    float avg;//평균
public:
    void setName(){
    cin>>name;
    }
    char *getName(){
    return name;
    }
 
    void setscore(int a){
    cin>>score[a];
    }
    int getscore(int a){
    return score[a];
    }
        
    int getTot(){
    return score[3]=score[0]+score[1]+score[2];
    }
    
    float getAvg(){
    return avg=score[3]/3.f;
    }
 
};
void main()
{
    int num;
    char a;
    int b;
 
    cout<<"How many people?";
    cin>>num;
 
    Student *sc;
    sc=new Student[num];
    
    for(int i=0;i<num;i++){
        cout<<"Name input: ";
        sc[i].setName();
 
        for(int j=0;j<3;j++){
            cout<<"Score input: ";
            sc[i].setscore(j);
        }
    }
 
    for(int i=0;i<num;i++){
        cout<<sc[i].getName()<<"\t";
        for(int j=0;j<3;j++){
            cout<<sc[i].getscore(j)<<"\t";
        }
        cout<<sc[i].getTot()<<"\t";
        cout<<sc[i].getAvg()<<endl;
    }
    delete []sc;
}


'code > C++' 카테고리의 다른 글

[C++] 다중 상속  (0) 2017.04.20
[C++] 성적처리 동적리턴  (0) 2017.04.20
[C++] Stack&Queue (예외처리, 소멸자 포함)  (0) 2017.04.20
[C++] 오버로딩-암시적 오버로딩  (0) 2017.04.20
[C++] 오버로딩- 명시적 로딩  (0) 2017.04.20

+ Recent posts