개인, 이름, ID #, 주소 및 전화 번호에 대한 여러 클래스를 만드는 것이 내 과제입니다.C++ 텍스트 메뉴 : 데이터 쓰기, 읽기 및 정렬
이름 구성 : 이름, 성, 이름. ID 번호 : 9 자리. 주소는 다음을 구성합니다 : 거리, 도시, 주 및 5 자리 우편 번호. 전화 번호는 3 자리 숫자와 7 자리 숫자로 구성됩니다. 전체 이름 (이름, 중간, 성), 주소, 전화 번호 (지역 번호 및 번호) 및 ID 번호 (9 자리 번호)로 구성됩니다.
나는이 모든 것을 성취했다. 내 문제는 우리가 메뉴를 만들고, 사용자가 입력하고자하는 사람의 수, 파일을 저장하려는 사람, 사용자가 지정한 파일을 읽거나 쓸 수 있는지, 그리고 가능한지 지정하는 것이다. (마지막, 처음 또는 중간) 또는 ID #별로 사람들을 정렬하고 정렬 된 목록을 사용자가 지정한 파일에 저장합니다.
필자는 모든 코드를 작성했지만 작성 기능이 작동하지 않습니다. 어떻게됩니까? 제가 만든 프로그램을 실행하면 팝업 메뉴가 나타납니다. '1'을 선택하여 파일을 입력 한 다음 메뉴가 다시 팝업되고 '2'를 선택하여 테스트중인 특정 파일에 아무것도 없으므로 '2'를 선택하여 읽을 수 없습니다. 다음으로 사용자 지정 파일에 People을 쓰려면 '3'을 선택합니다. 얼마나 많은 사람들이 들어가길 원하는지 물어보고 숫자를 입력합니다 (2).
//global variables
char filename[256];
fstream file2 (filename);
int r;
Person * stuArrPtr=new Person[r];
int w;
Person * stuArrPtr2=new Person[w];
//global functions
void WriteUserFile() {
//write as many ppl as specified to a file...
// int w;
cout << "How many students would you like to enter?: ";
cin >> w;
// Person * stuArrPtr2=new Person[w];
if (!file2.is_open()) {
cout << "File did not open" << endl;
file2.clear();
file2.open (filename, ios_base::out);
file2.close();
file2.open (filename, ios_base::out | ios_base::in);
}
else {
for (int i = 0; i < w/*!file2.eof()*/; i++) {
stuArrPtr2[i].InputPerson();
if (strcmp(stuArrPtr2[i].PersonNam.GetFirst(), "EOF") != 0)
stuArrPtr2[i].Display (file2);
}
}
cout << endl;
// delete [] stuArrPtr2;
}
void Menu() {
int option;
do {
//display menu
cout << " Type '1' - to open a file for reading or writing" << endl << endl;
cout << " Type '2' - to read from the file you specified in '1'" << endl << endl;
cout << " Type '3' - to write from the file you specified in '1'" << endl << endl;
cout << " Type '4' - sort students by last name" << endl << endl;
cout << " Type '5' - sort students by first name" << endl << endl;
cout << " Type '6' - sort students by middle name" << endl << endl;
cout << " Type '7' - sort students by ID number" << endl << endl;
cout << " Type '8' - exit" << endl << endl;
// cout << " Enter appropriate number here: [ ]\b\b";
cout << " Enter appropriate number here: ";
cin >> option;
switch(option) {
case 1:
cout << "you entered option 1" << endl;
OpenUserFile();
break;
case 2:
cout << "you entered option 2" << endl;
ReadUserFile();
break;
case 3:
cout << "you entered option 3" << endl;
WriteUserFile();
break;
case 4:
cout << "you entered option 4" << endl;
SortLastName();
break;
case 5:
cout << "you entered option 5" << endl;
SortFirstName();
break;
case 6:
cout << "you entered option 6" << endl;
SortMiddleName();
break;
case 7:
cout << "you entered option 7" << endl;
SortIDNumber();
break;
case 8:
cout << "you entered option 8" << endl; //exit
delete [] stuArrPtr;
delete [] stuArrPtr2;
break;
default:
cout << "you screwed up, no big deal, just try again!" << endl;
} //end switch
//if (option == 6) {
// break;
//}
} while (option != 8);
// system("pause");
}
void main() {
Menu();
}
/////////////////END OF CODE///////
죄송합니다 : 여기에
내 코드입니다 ... 첫 번째 이름을 입력에 대한 프롬프트가 뜨고 내 프로젝트 .exe로 "처리되지 않은 win32에서 예외가 발생했습니다"라는 몇 가지 오류 코드가 너무 길어서 어떤 도움을 주셔서 감사합니다!
코드를 재구성 할 수 있습니까? 4 칸만큼 들여 씁니다. – Lucas
적어도 코드 부분이 1 블록이라는 코드를 다시 포맷 해 주실 수 있습니까? 감사합니다 – fritzone
다음은 코드를 편집하는 방법입니다. http://stackoverflow.com/editing-help – Lucas