U E D R , A S I H C RSS

C++스터디_2005여름/학점계산프로그램/허아영


학점계산프로그램/허아영

솔직히 부끄럽습니다. C도 모르는데, C++로 이렇게 어려운 것을-_- ;;
정말 힘들게 풀었습니다. 물론 답이 맞는지도 모르겠구요.
OOP도 잘 모르는데,, -.- ;;
제 소스가 C++의 특징인 OOP를 사용하지 않은 껍데기 소스라고 보창오빠는 말하더군요 ㅠㅠ( 상처ㅡㅡ++++++ )
여튼 했으니 올립니다 !
// 파일출력하려다가, 표준출력 했습니다.

소스

calculate.h

~cpp 
#include <fstream>
#include "const.h"
#include "student.h"

class Calculate
{
private:
	Student a;
	
public:	
	
	void input();//파일입력, 학점으로 전환
	void Calculate_grade();
	//void output();//파일출력
};

student.h

~cpp 
#ifndef STUDENT_H_
#define STUDENT_H_

#include "const.h"

class Student
{
private:
	char name[STUDENT_NUM][10];
	double credit_average[STUDENT_NUM];
	//장학생 명단을 찍어내기 위한 변수
	//char sort_grade_name[STUDENT_NUM][10];
	//double sort_grade[STUDENT_NUM];
	
public:
	Student();
	void name_find(); // 이름을 파일에서 받아서 저장.
	void average();   // 평균을 계산하여 저장. 
	void sort();      // 학점평균이 높은 순으로 저장.
	void scholarship();//장학금, 학고 학생 출력,
	
	double grade[STUDENT_NUM][SUBJECT_NUM];	
};

#endif

const.h

~cpp 
#define SUBJECT_NUM 4
#define STUDENT_NUM 120
#define SCHOLARSHIP_NUM 12

calculate.cpp

~cpp 
#include <iostream>
using namespace std;

#include <fstream>
#include "calculate.h"
#include "student.h"

void Calculate::input()
{
	char temp[20];
	char grade_input[SUBJECT_NUM][3];
	double credit[9] = {4.5, 4.0, 3.5, 3.0, 2.5, 2.0, 1.5, 1.0, 0}; //학점
	char grade_data[9][3] = {"A+", "A", "B+", "B", "C+", "C", "D+", "D", "F"};
	
	fstream fin("input.txt");
	
	for(int student_num = 0; student_num < 120; student_num++)
	{
		fin.getline(temp, 20, ':');
		for(int i = 0; i < SUBJECT_NUM; i++)
		{
			fin.get();
			fin >> grade_input[i];
			for(int j = 0; j < 9; j++)
			{
				if(strcmp(grade_input[i], grade_data[j]) == 0)
					a.grade[student_num][i] = credit[j];
			}
		}
	}
}
/*
void Calculate::output()
{
	fstream fout("output.txt");
}
*/
void Calculate::Calculate_grade()
{
	a.name_find();
	a.average();
	a.sort();
	a.scholarship();
}

student.cpp

~cpp 
#include <iostream>
using namespace std;

#include <fstream>
#include "student.h"
#include "calculate.h"
#include "const.h"

Student::Student()
{
	for(int j = 0; j < STUDENT_NUM; j++)
	{
		credit_average[j] = 0.0;
		for(int i = 0; i < SUBJECT_NUM; i++)
			grade[j][i] = 0;
	}
}

void Student::name_find()
{
	char temp[20];
	fstream fin("input.txt");
	for(int i = 0; i < STUDENT_NUM; i++)
	{
		fin.getline(name[i], 10, ':');
		fin.getline(temp, 20, 'n');
	}
}

void Student::average()
{
	
	double sum = 0;
	for (int j = 0; j < STUDENT_NUM; j++)
	{
		for(int i = 0; i < SUBJECT_NUM; i++)
			sum += grade[j][i];
		credit_average[j] = (double)(sum/SUBJECT_NUM);
		sum = 0;
	}
}

void Student::scholarship()
{
	//fstream fout("output.txt");
	cout << "학고 명단" << endl;
	for(int i = 0; i < STUDENT_NUM; i++)
	{
		if(credit_average[i] <= 1.5)
			cout << name[i] << endl;
	}
	cout << "장학생 명단" << endl;
	for(i = 0; i < SCHOLARSHIP_NUM; i++)
	{
		cout << name[i];
		cout << endl;
	}
	
}

void Student::sort()
{
	char temp[10];
	double temp_grade;
	for(int i = 0; i < STUDENT_NUM; i++){
		for(int j = i; j < STUDENT_NUM; j++){
			if(credit_average[i] <= credit_average[j])
			{
				temp_grade = credit_average[i];
				credit_average[i] = credit_average[j];
				credit_average[j] = temp_grade;
				strcpy(temp, name[j]);
				strcpy(name[j], name[i]);
				strcpy(name[i], temp);
			}
		}
	}		
}

source.cpp

~cpp 
#include <iostream>
#include <fstream>
#include "calculate.h"
#include "student.h"

using namespace std;

void main()
{
	Calculate a;	
	
	a.input();
	a.Calculate_grade();
}

나에게 할말

오옷.. 근래 본 메인함수중에 가장 심플한 함수였어~ 왠지 Hellow world!! 도 이보단 못할듯.ㅎ
C++의 탈을쓴 C...나잖아..;;ㅁ;; 후훗..ㅎ
괜찮아 괜찮아~! 인생 모이떠~ 막 가눈고야~~>ㅃ<;;
음.. 동기를 안좋은 곳으로 끌어들이다닛..나쁜아이.훗..
칼큘레이트(귀차니즘으로 영어 생략)함수와 스튜던트 함수 양쪽에서 둘다 파일 입출력 하는게 있는것 같은데..
아예 한쪽은 죽어라 입출력 계산만 하고 한쪽은 자료보관만 하는계 좀더 깔끔했을지도~
후후후.. 실은 나도 모르겠.. (C++을 배운적이 있어야.훗.) 뭐..하나만 잘하면 되지..ㅎㅎ 아영이만큼 C만 하면 조케따~>ㅁ<;;
자자~ 그럼 힘내서 오늘도 즐겁게 놀자고~'ㅇ')/ 곧 개강이니까.훗..ㅎ 좋은하루!- 조현태
----
허아영 C++스터디_2005여름 C++스터디_2005여름/학점계산프로그램
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:22:46
Processing time 0.0152 sec