Last active
September 29, 2015 12:13
-
-
Save gokuorzzl/3c6169036ec2f8583e7f to your computer and use it in GitHub Desktop.
C++_실습3-1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
전화번호 관리 프로그램 -매니저에서 하고, | |
기능 1 : 전화번호부 사람추가(이름, 직업, 주소 , 전화번호) | |
>> 클래스, 각변수에 이름, 직업, 주소, 전번 선언 | |
기능 2 : 사람 검색 (이름) // user에서 검색돕고, | |
>> 클래스 user | |
기능 3 : 사람 정보 수정 ( 주소, 전화번호) // 매니저에서 하자. | |
>> 유저클래스에서 수정 할수잇도록, 주소, 전화번호를 퍼블릭에. | |
기능 4 : 전체 전화번호부 출력 (모니터 출력) | |
>> | |
기능 q : 프로그램 종료 | |
프로그램 종료전까지는 커멘드를 계속 띄우도록 | |
각기능을 나누기위해서는 먼저는 커멘드가 필요함. | |
각기능때마다 기능에 맞는 함수를 실행해주고, | |
- 전번관리를 위해 매니저 클래스, user_list클래스, 전화번호 클래스가 있어야된다. | |
전화번호부의 저장구조 >> 구조체변수배열 AddList배열 사용. | |
기본검색 사람이름만 검색 | |
*/ | |
#include <iostream> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#define MAX_ADDRESS 20 | |
using namespace std; | |
struct Date{ | |
int year; // 입력 년도 | |
int month; // 입력 월 | |
int day; // 입력 일 | |
}; | |
struct Person{ | |
char Name[10]; // 사람이름 | |
char Address[20]; // 주소 | |
char Phone[15]; // 전화번호 | |
Date date; | |
}; | |
void Add(); | |
void Search(); | |
void Edit(); | |
void Show(); | |
int Menu(); | |
Person AddList[MAX_ADDRESS]; | |
int Address_Num =0; | |
int main() { | |
// 전화번호부 저장구조 간편화를 위해 각 객체이름저장을 AddList에 한다. | |
//Person user[10]; | |
//10개의 데이터 | |
Menu(); | |
} | |
int Menu(){ | |
char n; | |
printf("전화번호관리 프로그램 version 1.0\n\n"); | |
while(1){ | |
printf("아래의 메뉴에서 원하는 기능을 선택\n\n"); | |
printf(" 1 : 전화번호부 사람추가(이름, 주소 , 전화번호)\n"); | |
printf(" 2 : 사람 검색 (이름)\n"); | |
printf(" 3 : 사람 정보 수정 ( 주소, 전화번호)\n"); | |
printf(" 4 : 전체 전화번호부 출력 (모니터 출력)\n"); | |
printf(" Q : 프로그램 종료\n\n"); | |
fflush(stdin); // 키보드 버퍼제거 (안하면 무한루프) | |
n = getchar(); // scanf를 쓸경우 종료 및 스위치문 정상 작동이 잘안됨. 왜그럴까? | |
switch(n){ | |
case '1': | |
Add(); | |
break; | |
case '2': | |
Search(); | |
break; | |
case '3': | |
Edit(); | |
break; | |
case '4': | |
Show(); | |
break; | |
case 'Q': | |
printf("프로그램을 종료합니다\n"); | |
return 0; | |
}// switch | |
}//while | |
} | |
//전화번호 추가 함수 | |
void Add(){ | |
fflush(stdin); | |
printf("추가 하실 분의 정보를 입력하세요. \n이름:"); | |
gets(AddList[Address_Num].Name); | |
printf("주소:"); | |
gets(AddList[Address_Num].Address); | |
fflush(stdin); | |
printf("전화번호:"); | |
gets(AddList[Address_Num].Phone); | |
fflush(stdin); | |
printf("등록 일 : 년, 월, 일"); | |
scanf("%d %d %d", &AddList[Address_Num].date.year, | |
&AddList[Address_Num].date.month, &AddList[Address_Num].date.day); | |
Address_Num++; // 등록 카운트 1증가 | |
} | |
void Search(){ | |
bool boolean = false; // false : 검색실패, true : 검색성공 | |
char name[10]; //검색을 원하는 사원이름 저장 | |
printf("검색할 분의 이름:"); | |
scanf("%s", &name); | |
for(int i=0; i<Address_Num; i++){ | |
if(strcmp(AddList[i].Name, name)==0){ | |
//char[]의 비교는 strcmp함수를 써야됨. | |
printf("[%d] 이름: %s 주소: %s 연락처: %s \n 입력일: %d년 %d월 %d일\n\n", | |
i+1, AddList[i].Name, AddList[i].Address, AddList[i].Phone, | |
AddList[i].date.year,AddList[i].date.month, AddList[i].date.day); | |
boolean = true; | |
// 구조체안에 변수를 포인터로 변경시 작동이 안되었다. | |
// 어떻게 해야될까... | |
} | |
} | |
if(boolean == false) | |
printf("검색한 이름이 없습니다.\n"); | |
} | |
void Edit(){ | |
bool boolean = false; // false : 검색실패, true : 검색성공 | |
char name[10]; //검색을 원하는 사원이름 저장 | |
char temp[20]; //주소입력 | |
int cmd=0; | |
printf("현재 주소, 전화번호 수정 가능합니다.\n"); | |
printf("수정할 사람의 이름:"); | |
scanf("%s", &name); | |
fflush(stdin); | |
for(int i=0; i<Address_Num; i++){ | |
if(strcmp(AddList[i].Name, name)==0){ | |
boolean = true; | |
// 기본정보 출력 | |
printf("기존의 정보: %s %s %s\n\n", AddList[i].Name, | |
AddList[i].Address, AddList[i].Phone); | |
// 수정 커멘드 choice | |
//fflush(stdin); | |
//없으면 그냥 넘어가네요. | |
printf("수정목록을 입력해주세요.(주소:1, 전화번호:2) : "); | |
fflush(stdin); | |
scanf("%d", &cmd); | |
if(cmd==1){ | |
printf("수정 주소: "); | |
scanf("%s", &temp); //scanf는 무조건 입력만 받도록쓰자. 출력안됨. | |
strcpy(AddList[i].Address, temp); | |
} | |
else if(cmd==2){ | |
printf("수정 전화번호: "); | |
scanf("%s", &temp); | |
strcpy(AddList[i].Phone, temp); | |
} | |
else | |
printf("잘못된 값입니다."); | |
} | |
} | |
if(boolean == false) | |
printf("검색한 이름이 없습니다.\n"); | |
} | |
void Show(){ | |
for(int i=0; i<Address_Num; i++){ | |
printf("[%d] 이름: %s 주소: %s 연락처: %s \n 입력일: %d년 %d월 %d일\n", i+1, | |
AddList[i].Name, AddList[i].Address, AddList[i].Phone, | |
AddList[i].date.year,AddList[i].date.month, AddList[i].date.day); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment