C++ 프로그래밍 기초, 7장 연습문제
Posted 2008/10/10 11:25, Filed under: 학과수업들/C++ 프로그래밍
#include<iostream>
using namespace std;
struct sungjuk{
char name[20];
int kor;
int eng;
int mat;
int tot;
double ave;
};
void totAve(sungjuk &s);
void prn(sungjuk s);
void main()
{
sungjuk s = {"성윤정",100,80,95};
totAve(s); //총점과 평균
prn(s); //출력
}
void totAve(sungjuk &s)
{
s.tot = s.kor + s.eng + s.mat;
s.ave = s.tot / 3.0;
}
void prn(sungjuk s)
{
cout<<"\n이름\t국어\t영어\t수학\t총점\t평균";
cout<<"\n -------------------------------------------";
cout<<"\n"<<s.name<<"\t"<<s.kor<<"\t"<<s.eng<<"\t"<<s.mat<<"\t"<<s.tot<<"\t"<<s.ave<<"\n";
}
#include<iostream>
using namespace std;
struct sungjuk{
char name[20];
int kor;
int eng;
int mat;
int tot;
double ave;
};
void init(sungjuk &s);
void totAve(sungjuk &s);
void prn(sungjuk s);
void main()
{
sungjuk s;
init(s);
totAve(s); //총점과 평균
prn(s); //출력
}
void init(sungjuk &s)
{
cout<<"이름을 입력하세요.-> ";
cin>>s.name;
cout<<"국어 점수를 입력하세요.-> ";
cin>>s.kor;
cout<<"영어 점수를 입력하세요.-> ";
cin>>s.eng;
cout<<"수학 점수를 입력하세요.-> ";
cin>>s.mat;
}
void totAve(sungjuk &s)
{
s.tot = s.kor + s.eng + s.mat;
s.ave = s.tot / 3.0;
}
void prn(sungjuk s)
{
cout<<"\n이름\t국어\t영어\t수학\t총점\t평균";
cout<<"\n -------------------------------------------";
cout<<"\n"<<s.name<<"\t"<<s.kor<<"\t"<<s.eng<<"\t"<<s.mat<<"\t"<<s.tot<<"\t"<<s.ave<<"\n";
}
#include<iostream>
using namespace std;
struct sungjuk{
char name[20];
int kor;
int eng;
int mat;
int tot;
double ave;
};
void init(sungjuk s);
void totAve(sungjuk &s);
void prn(sungjuk s);
void main()
{
sungjuk s[5];
for(int i=0; i<5; i++){
init(s[i]);
}
}
void init(sungjuk s)
{
cout<<"이름을 입력하세요.-> ";
cin>>s.name;
cout<<"국어 점수를 입력하세요.-> ";
cin>>s.kor;
cout<<"영어 점수를 입력하세요.-> ";
cin>>s.eng;
cout<<"수학 점수를 입력하세요.-> ";
cin>>s.mat;
cout<<"\n";
totAve(s);
prn(s);
}
void totAve(sungjuk &s)
{
s.tot = s.kor + s.eng + s.mat;
s.ave = s.tot / 3.0;
}
void prn(sungjuk s)
{
cout<<"\n이름\t국어\t영어\t수학\t총점\t평균";
cout<<"\n -------------------------------------------";
cout<<"\n"<<s.name<<"\t"<<s.kor<<"\t"<<s.eng<<"\t"<<s.mat<<"\t"<<s.tot<<"\t"<<s.ave<<"\n";
}
Response :
0 Trackback
,
0 Comment
Trackback URL : http://mysilpir.net/trackback/317
