class student
{
private:
int number;
char name[20];
int grade;
int year;
int phonenumber;
public:
student(char name[], int Grade, int Year, int Phonenumber);
student();
void get_info(char name[], int Grade, int Year, int Phonenumber);
void get_info();
void input_num(int num);
int get_num();
};
#include<stdio.h>
#include"user.h"
#include<stdlib.h>
#pragma warning(disable : 4996)
int main()
{
int flag;
student *user[50];
char tempname[20];
int tempgrade;
int tempyear;
int tempphone;
for (int i = 0; i < 50; i++)
{
printf("\n학생정보를 입력하세용~ 1 입력 1 이외 노입력\n");
scanf("%d", &flag);
if(flag == 1)
{
printf("이름 : ");
scanf("%s", tempname);
printf("학년 : ");
scanf("%d", &tempgrade);
printf("기수 : ");
scanf("%d", &tempyear);
printf("폰번 : ");
scanf("%d", &tempphone);
user[i] = new student(tempname, tempgrade, tempyear, tempphone);
}
else
{
user[i] = new student();
}
}
}
#include<stdio.h>
#include<string.h>
#include"user.h"
#pragma warning(disable : 4996)
student::student(char Name[], int Grade, int Year, int Phonenumber){
strcpy(name, Name);
grade = Grade;
year = Year;
phonenumber = Phonenumber;
printf("이름은 %s 학년은 %d 기수는 %d 폰번은 %d!",name,grade,year,phonenumber);
printf("\n잘부탁드립니다!");
}
student::student(){
printf("------고학번만 볼수 있는 문장입니다------");
printf("\n잘부탁드립니다!");
}
void student::get_info(char Name[], int Grade, int Year, int Phonenumber){
strcpy(name, Name);
grade = Grade;
year = Year;
phonenumber = Phonenumber;
printf("이름은 %s 학년은 %d 기수는 %d 폰번은 %d!", name, grade, year, phonenumber);
printf("\n잘부탁드립니다!\n");
}
void student::get_info(){
printf("------고학번만 볼수 있는 문장입니다------");
printf("\n잘부탁드립니다!\n");
}
int student::get_num()
{
return number;
}
void student::input_num(int num)
{
number = num;
}
- 갠적으로는 생성자 없이 구조체 할당하는데에서 애좀 먹음 ;;;;