#페이스북

언어/c언어2017. 10. 9. 09:09

/* 작성자 : sleep4725.tistory.com */

/* 작성일 : 2017_10_09_한글날 */

/* 테스트 환경 : win10, visual studio 2013 */

# include <stdio.h>

# include <string.h>

# include <stdlib.h>

# define LEN 50

typedef struct _InfoStu

{

char stuDentName[LEN];

unsigned int Info_Hangle; // 국어

unsigned int Info_Eng; // 영어 

unsigned int Info_Math; // 수학

unsigned int Info_Attend; // 출결

unsigned int Info_TotalScore; // 총점

double Info_avg; // 네과목의 평균

}InfoStu, *ptrInfo;

// ====================================================

// 함수 원형

ptrInfo _CreateNode_(); // [1] 

void _Init_(InfoStu** nParam); // [2]

void _StuNameWrite_(InfoStu** nParam); // [3]

void _StuScoreWrite_(InfoStu** nParam); // [4]

void _ScoreTotal_(InfoStu** nParam); // [5]

void _ScoreAverage_(InfoStu** nParam); // [6]

void _StudentInformationData_(InfoStu** nParam); // [7]

// ====================================================

int main(void)

{

ptrInfo MyStu = NULL;

MyStu = _CreateNode_();

_Init_(&MyStu);

_StuNameWrite_(&MyStu);

_StuScoreWrite_(&MyStu);

_ScoreTotal_(&MyStu);

_ScoreAverage_(&MyStu);

_StudentInformationData_(&MyStu);

free(MyStu);

return 0;

} // end of main function

ptrInfo _CreateNode_() // [1]

{

ptrInfo cNode = (ptrInfo)malloc(sizeof(InfoStu));

_Init_(&cNode);

return cNode;

} // end of createNode function 

// ====================================================

void _Init_(InfoStu** nParam) // [2]

{

if ((*nParam) == NULL)

{

fprintf(stderr, "malloc error... !!!\n");

exit(1);

}

else

{ // (*nParam) != NULL

(** nParam).Info_Attend = 0; // type int

(** nParam).Info_avg = 0.0; // type double

(** nParam).Info_Eng = 0;

(** nParam).Info_Hangle = 0;

(** nParam).Info_Math = 0;

(** nParam).Info_TotalScore = 0;

strcpy((** nParam).stuDentName, "\0");

}

} // end of _Init_ function

// ====================================================

void _StuNameWrite_(InfoStu** nParam) // [3]

{

printf("학생의 이름: ");

fgets((** nParam).stuDentName, LEN, stdin);

(** nParam).stuDentName[strlen((** nParam).stuDentName) - 1] = '\0';

} // end of _StuNameWrite_ function

// ====================================================

void _StuScoreWrite_(InfoStu** nParam) // [4]

{

printf("국어 : ");

scanf("%d", &((** nParam).Info_Hangle));


printf("영어 : ");

scanf("%d", &((** nParam).Info_Eng));


printf("수학 : ");

scanf("%d", &((** nParam).Info_Math));


printf("출결 : ");

scanf("%d", &((** nParam).Info_Attend));


system("cls");


} // end of _StuScoreWrite_ function 

// ====================================================

void _ScoreTotal_(InfoStu** nParam) // [5]

{

(** nParam).Info_TotalScore = 

(** nParam).Info_Eng + // 영어 

(** nParam).Info_Hangle + // 한글

(** nParam).Info_Math; // 수학

} // end of _ScoreTotal_ function

// ====================================================

void _ScoreAverage_(InfoStu** nParam)

{

(** nParam).Info_avg = (double)((** nParam).Info_TotalScore / 3);

} // end of _ScoreAverage_ function 

// ====================================================

void _StudentInformationData_(InfoStu** nParam)

{

printf("======[ student information ]======= \n");

printf("[1] 한생이름  =====> [ %s ] \n", (**nParam).stuDentName);

printf("[2] 국어 점수 =====> [ %2d ] \n", (**nParam).Info_Hangle);

printf("[3] 영어 점수 =====> [ %2d ] \n", (**nParam).Info_Eng);

printf("[4] 수학 점수 =====> [ %2d ] \n", (**nParam).Info_Math);

printf("[5] 출결 점수 =====> [ %2d ] \n", (**nParam).Info_Attend);

printf("[6] 총점      =====> [ %2d ] \n", (**nParam).Info_TotalScore);

printf("[7] 평균      =====> [ %.2f ] \n", (**nParam).Info_avg);

printf("==================================== \n");

} // end of _StudentInformationData_ function 

// ====================================================

'언어 > c언어' 카테고리의 다른 글

네이버 풀이 나  (0) 2017.10.13
진행중  (0) 2017.10.13
#네이버  (0) 2017.10.08
lotto 관련 코드 네이버 답변  (0) 2017.10.08
transpose matrix  (0) 2017.10.07