링크드리스트 학생관리

Programming/C,CPP,CS 2013. 1. 19. 16:32 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

#include <iostream>

#include <stdio.h>

using namespace std;


typedef struct student_t

{

int lan;

int eng;

int mat;

struct student_t* p;

}student_t;

student_t* makeStudent()

{

student_t* curr = (student_t*)malloc(sizeof(student_t));

cin >> curr->lan;

cin >> curr->eng;

cin >> curr->mat;

curr->p = NULL;

return curr;

}

int main()

{

student_t* head;

student_t* temp;

int stuSum[1];

int lecSum[3] = {0};

int totalSum = 0;

int i, j, k;

head = (student_t*)malloc(sizeof(student_t));

head->p = NULL;

for( i = 0 ; i < 10000 ; i++ )

{


temp = head;

while( temp->p != NULL )

{

temp = temp->p;

}

temp->p = makeStudent();


cout << "계속 하시겠습니까? (y/n): " ;

char mode;

cin >> mode;

if( mode == 'n')

{

break;

}

}

cout << "결과 출력 ===================" << endl;

printf("%3s %4s %4s %4s\n", "번호" , "국어" , 

"영어" , "수학" );

temp = head->p;

i = 0;

while( temp != NULL )

{

lecSum[0] = temp->lan;

lecSum[1] = temp->eng;

lecSum[2] = temp->mat;

printf("%3d %4d %4d %4d\n", i+1 , temp->lan , 

temp->eng , temp->mat );

temp = temp->p;

i++;

}

printf("    %4d %4d %4d \n", lecSum[0] , 

lecSum[1] , lecSum[2]);

free(temp);

}