U E D R , A S I H C RSS

C++스터디_2005여름/학점계산프로그램/정수민

소감

이제 된다 T^T
구조는 거의다 보창이형껄 배꼈지만 ;;
나름대로 열시미한 =ㅅ=

코드

Grade.h

~cpp 
#ifndef GRADE_H_ 
#define GRADE_H_ 

#include "student.h"

class Grade
{
private:
        Student * students;

public:
        Grade();
        void show_good_student();
        void show_bad_student();
		void show_all_student();
        ~Grade();
};

#endif

Grade.cpp

~cpp 
#include <iostream>
using namespace std;
#include "grade.h"
#define MAX_STUDENT 121

Grade::Grade()
{
	students = new Student[MAX_STUDENT];

	for (int i=1;i<MAX_STUDENT;i++) {
		students[i].input();
	}
}

void Grade::show_good_student()
{
	double compare=4.5;
	int num=MAX_STUDENT/10;
	int good_student_number=0;

	cout << "장학생 명단\n";
	while (1) 
	{
		int i,j;
		double temp=4.5;
		for (i=1;i < MAX_STUDENT;i++)
		{
			if (compare-students[i].average < temp &&
				compare-students[i].average > 0 )
			{
				temp=compare-students[i].average;
				j=i;
			}
		}

		for (i=1;i < MAX_STUDENT;i++)
		{
			if (compare-students[i].average == temp) {
				students[i].show();
				good_student_number++;
			}
		}

		compare=students[j].average;

		if (good_student_number>num) 
		{
			break;
		}
	}
	cout << "\n\n";
}

void Grade::show_bad_student()
{
	cout << "학고 명단\n";
	for (int i=1;i<MAX_STUDENT;i++)
	{
		if (students[i].average<1.5)
			students[i].show();
	}
	cout << "\n\n";
}

void Grade::show_all_student()
{
	for (int i=1;i<MAX_STUDENT;i++)
	{
			students[i].show();
	}
	cout << "\n\n";
}

Grade::~Grade()
{
	delete [] students;
}

Student.h

~cpp 
#ifndef STUDENT_H_ 
#define STUDENT_H_ 


class Student
{
private:
	int school_number;
	double grade[4];

public:
	Student();

	double average;
	void input();
	void show();
	void get_average();
};

#endif

Student.cpp

~cpp 
#include <iostream>
#include <fstream>
using namespace std;

#include "student.h"


Student::Student()
{
	average = 0.0;
	school_number = 0;
}

void Student::input()
{
	static fstream fin("input.txt");

	char str[3];
	double sum = 0.0;
	int i;

	fin.ignore(100, ' ');

	fin >> school_number;

	fin.ignore(100, ':');

	for (i=0;i<4;i++)
	{
		fin >> str;
		if (str[0]=='F') 
		{
			grade[i] = 0;
		}
		else
		{
			grade[i] = ((int)'F'-1)-(int)str[0];
		}
		if (str[1]=='+'){
			grade[i]+=0.5;
		}
	}
	fin.ignore(100, '\n');


	for (i=0;i<4;i++){
			sum += grade[i];
	}
	average = sum/4;
}

void Student::show()
{
        cout << "학번 : " << school_number << "   평점 : " << average << endl;
}

main.cpp

~cpp 
#include "grade.h"
#include <iostream>
using namespace std;

void main()
{
	Grade str;
	str.show_good_student();
	str.show_bad_student();
	str.show_all_student();
/*	char
		str1[3]="A+"
		;
	double
		sum1 = 0.0,
		average1
		;
	int
		i1
		;

	average1=((int)'F'-1)-(int)str1[0];
	if (str1[1]=='+'){
		average1+=0.5;
	}
	cout<<average1<<endl;
	cout<<(int)str1[0]<<endl<<(int)str1[1]<<endl<<(int)str1[2];
*/}
}

나한테 할 말

헤... 오빠 멋쪄어~~>ㅁ<;;;
나는 C++같은거 안배워서 모르겠다모~@0@ 검은건 글이고 흰건 배경이얌~>ㅃ<;;
모르긴 몰라도 이정도면 잘한고 같운데..ㅎ 숫자를 앞에 상수로 선언하면 더욱더 좋겠지만...ㅎ 구래두 잘해떵~>ㅁ<:;
헤헤헤.. 개강하고 우리 수사마(엥;;) 에게 배워야 겠눈뎅..ㅎ
구럼 개강하고 봐~~ 뱌뱌~'ㅇ')/ - 조현태

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:22:46
Processing time 0.0278 sec