(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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include<iostream>
 
using namespace std;
 
void hNum(int &num);
void input(int num,char name [][10],int score[][4]);
void oper(int num,int score[][4], float avg[]);
void disp(int num,char name[][10],int score[][4],float avg[]);
int wmam(int num,char (**name)[10],int (**score)[4],float **avg);
void ddelete(char name[][10],int score[][4], float avg[]);
int *reScore(int num);
char *reNamee(int num);
float *reAvg(int num);
 
const static char scoName[6][10]={"Name","Kor","Eng","Mat","Total","Avg"};
void main(){
 
    int num=0;
    char(*name)[10]={0,};
    int (*score)[4]={0,};
    float (*avg)={0,};
 
    hNum(num);
    name=(char(*)[10])reNamee(num);
    score=(int(*)[4])reScore(num);
    avg=(float (*))reAvg(num);
 
    input(num,name,score);
    oper(num,score,avg);
    disp(num,name,score,avg);
 
    ddelete(name,score,avg);
}
void hNum(int &num){
    cout<<"How many people? ";
    cin>>num;
}
 
void ddelete(char name[][10],int score[][4], float avg[]){
    delete[]name;
    delete[]score;
    delete[]avg;
}
 
char *reNamee(int num){
    return new char [num*10];
}
 
int *reScore(int num){
    return new int [num*4];
}
 
float *reAvg(int num){
    return new float[num];
}
 
void input(int num,char name [][10],int score[][4]){//void input(char name[][10],int score[][4])
    for(int i=0;i<num;i++){
        cout<<*scoName<<" Input: "//항상 주소는 1차 주소값으로
        cin>>*(name+i);
 
        for(int j=0;j<3;j++){
            cout<<scoName[j+1]<<" Input: ";
            cin>>score[i][j];
        }
    }
}
void oper(int num,int score[][4], float avg[]){
 
    for(int i=0;i<num;i++){
        score[i][3]=0;
        for(int j=0;j<3;j++){
            score[i][3]+=score[i][j];
        }
        avg[i]=score[i][3]/3.f;
    }    
}
void disp(int num,char name[][10],int score[][4],float avg[]){
    for(int i=0;i<6;i++){
        cout<<scoName[i]<<"\t";
    }
    cout<<endl;
    for(int i=0;i<num;i++){
        cout<<name[i]<<"\t"//항상 주소는 1차 주소값으로
        for(int j=0;j<4;j++){
            cout<<score[i][j]<<"\t";
        }
        cout<<avg[i]<<endl;
    }
}


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

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

+ Recent posts