C++ 프로그래밍 질문입니다.

alal0614의 이미지

제가 C++배우고 처음으로 혼자서

정말 간단한 스케줄관리(?)프로그램을 만들고 있는데

실행할때 에러는 안뜨는데....

수정과 삭제부분에서 오류가 납니다.ㅠㅠㅠㅠㅠ

수정을 하고 조회를 하면 그 바뀐 부분에 외계어같은게 뜨고

삭제를 하고 조회를 하면 없어져야할 스케줄이 외계어로 나옵니다 ㅠㅠㅠㅠ

왜이러는 걸까요ㅠㅠㅠ

#include
using namespace std;
const int DAY_LEN = 20;
const int TODO_LEN = 20;

void InputSchedule();
void ModifySchedule();
void DeleteSchedule();
void InquireSchedule();
void printMenu();

class Schedule
{
protected :
char* day;
char* toDo;

public :
Schedule(){}
Schedule(char* day, char* toDo);
~Schedule();
char* gettoDo();
char* getday();
void ShowSchedule();
};

Schedule :: Schedule(char* day, char* toDo)
{
this->day=new char[strlen(day)+1];
strcpy(this->day, day);
this->toDo=new char[strlen(toDo)+1];
strcpy(this->toDo, toDo);

}

Schedule :: ~Schedule()
{
delete []toDo;
}

char* Schedule :: gettoDo()
{
return this->toDo;
}

char* Schedule :: getday()
{
return this->day;
}

Schedule* pArray[100];
int index = 0;

void Schedule :: ShowSchedule()
{
cout << "---------[스케줄 정보]---------" << endl;
cout << "날짜 : " << day << endl;
cout << "스케줄 : " << toDo << endl;
cout << "-------------------------------" << endl;
}
void printMenu()
{
cout << "---------------[메뉴]-----------------" << endl;
cout << "1. 스케줄 입력" << endl;
cout << "2. 스케줄 수정" << endl;
cout << "3. 스케줄 삭제" << endl;
cout << "4. 스케줄 조회" << endl;
cout << "5. 프로그램 종료" << endl;
cout << "--------------------------------------" << endl;
}

void InputSchedule()
{
char day[DAY_LEN];
char toDo[TODO_LEN];

cout << "------------[스케줄 입력]------------" << endl;
cout << "날짜 입력 : ";
cin >> day;
cout << "스케줄 입력 : ";
cin >> toDo;

pArray[index++] = new Schedule(day, toDo);
}

void ModifySchedule()
{
int i;
char day[DAY_LEN];
char toDo[TODO_LEN];

cout << "------------[스케줄 수정]------------" << endl;
cout << "찾으시는 날짜를 입력해 주세요." << endl;
cout << "날짜 입력 : ";
cin >> day;

for(i=0; i {
if(strcmp(pArray[i]->getday(), day)==0)
{
cout << "날짜 : " << pArray[i]->getday() << endl;
cout << "스케줄 : " << pArray[i]->gettoDo() << endl;
delete pArray[i]->gettoDo();

cout << "스케줄 수정 : ";
cin >> toDo;

cout << "스케줄 수정이 완료 되었습니다." < return;
}
}
cout<<"수정 할 스케줄이 없습니다.<

}

void DeleteSchedule()
{
char day[DAY_LEN];
int i;

cout << "---------[스케줄 삭제]---------" << endl;
cout << "삭제하려는 날짜를 입력해 주세요." << endl;
cout << "입력 : ";
cin >> day;

for(i=0; i {
if(strcmp(pArray[i]->getday(), day)==0)
{
delete pArray[i]->getday();
delete pArray[i]->gettoDo();

cout << "스케줄이 삭제되었습니다." < return;
}
}
cout<<" 삭제할 스케줄이 없습니다."< }

void InquireSchedule()
{
for(int i=0;i {
pArray[i]->ShowSchedule();
cout << endl;
}
}

enum{INPUT=1, MODIFY, DELETE, INQUIRE, EXIT};

void main(){

int menuNum;

while(1){

printMenu();
cout<<"메뉴 선택(1~5) : ";
cin>>menuNum;

switch(menuNum)
{
case INPUT :
InputSchedule();
break;
case MODIFY:
ModifySchedule();
break;
case DELETE :
DeleteSchedule();
break;
case INQUIRE :
InquireSchedule();
break;
case EXIT :
cout<<"프로그램이 종료됩니다. "< return;
default :
cout<<"1~5까지 수를 입력하세요"< break;
}
}
return;
}

라스코니의 이미지

어떤 툴을 쓰는지 모르겠지만 debug를 해보세요.
그리고 day란 이름을 같이 쓰고 있는데 서로 적당한 변수명으로 바꾸기만 해도 프로그램을 이해하고 디버그하기 쉬울 것 같습니다.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.