예제 #1
0
int main() {
    StudentList slist[5];//データオブジェクト, 今回は直接アクセスしないルール
    char nm[50];
    int id, grd; //入力のために使う変数
    StudentList *ptr; //セットのために使うオブジェクト、ポインタ差し替えで使う

    ptr = slist;
    for (int i=0; i<5; i++) {
        cout << i+1 << "人目のデータを入力します\n";
        cout << "名前を入力してください:";
        cin >> nm;
        cout << "学籍番号を入力してください:";
        cin >> id;
        cout << "学年を入力してください:";
        cin >> grd;
        ptr->set(nm,id,grd);
        ptr++;    // ポインタをデータ1個分インクリメント(加算)する=>次のデータ先頭へ!
    }
    //表示部
    ptr = slist; //ポインタをオブジェクト配列先頭に戻す
    for (int i=0; i<5; i++) {
        cout << "[" << i+1 << "]\t";
        ptr->show();
        ptr++;   //ここでもポインタをインクリメントして次のデータの先頭に移動します
    }

    return 0;
}
예제 #2
0
int main(int argc, char* argv[])
{
    using namespace std;
    StudentList students;
    read(std::cin, students);
   
    typedef map<string, vector<string> > Ranges;
    Ranges m;

    for(StudentList::const_iterator it = students.begin();
        it != students.end(); ++it) {
        m[grade_range(*it)].push_back(it->name);
        cout << it->name << " " << grade(*it) 
            << " " << grade_range(*it) << endl;
    }
    cout << string(10,'-') << endl;
    
    for(Ranges::const_iterator it = m.begin();
        it != m.end(); ++it) {
        const vector<string>& s = it->second;
        cout << it->first << "(" << s.size() << "):";
        for(vector<string>::const_iterator i = s.begin();
            i != s.end(); ++i)
            cout << " " << *i;
        cout << endl;
    }
    return 0;
}
예제 #3
0
void main()
{
    StudentList sList;
    sList.appendEntry(new Student("Mary Chen", "111111111", 
                                    "0933111111", "Business"));
    sList.appendEntry(new Student("John Wang", "222222222", 
                                    "0928222222", 
                                    "Computer Science"));
    sList.appendEntry(new Student("Mel Lee", "333333333", 
                                    "0968333333", 
                                    "Mechanical Engineering"));
    sList.appendEntry(new Student("Bob Tsai", "444444444", 
                                    "0930444444", 
                                    "Electrical Engineering"));
    sList.appendEntry(new Student("Ron Yang", "555555555", 
                                    "0918555555", 
                                    "Computer Science"));
        
    sList.find("222222222")->display(cout); cout << endl;

    if (sList.deleteEntry("444444444"))
        cout << "Bob Tsai's entry deleted successfully!\n";
    else
        cout << "Bob Tsai's entry deletion failed!\n";

    if (sList.find("444444444") == 0)
        cout << "Can not fine Bob Tsai's entry!\n";
	system("PAUSE");
}
예제 #4
0
int TaskManager::findStudent(StudentList& s_list, int id)
{
	// 학생 정보 검색
	for (int i = 0; i < s_list.getCount(); i++)
	{
		if (id == s_list.getStudentList(i).getId()) // id에 저장된 값(입력 값) == 출력된 값
		{
			return i; // 검색해서 찾은 값을 반환
		}
	}
}
예제 #5
0
void TaskManager::displayStudent(StudentList s_list)
{
	ioHandler ioh;

	ioh.putString(" 학생 정보를 출력합니다 ");

	for (int i = 0; i < s_list.getCount(); i++) // 출력을 계속 해주기 위해 반복
	{
		Student s = s_list.getStudentList(i);
		ioh.putStudent(s);
	}
}
예제 #6
0
void TaskManager::unregisterStudent(StudentList& s_list)
{
	ioHandler ioh;

	ioh.putString(" 학생 정보를 삭제합니다 ");

	int id = ioh.getInteger(" 삭제할 학생의 학번을 입력하시오 : ");

	for (int i = findStudent(s_list, id); i < s_list.getCount(); i++)
	{
		s_list.deleteStudent(i); // 전의 공간에 다음 공간을 덮어 씌워주는 배열 함수를 호출
	}
}
예제 #7
0
void TaskManager::registerStudent(StudentList& s_list)
{
	ioHandler ioh;

	ioh.putString(" 학생 정보를 등록합니다 ");

	Student s = ioh.getStudent();
	s_list.insertStudent(s); // 생성자의 내용을 배열 함수에 삽입
}
예제 #8
0
void TaskManager::changeStudent(StudentList& s_list)
{
	ioHandler ioh;

	ioh.putString(" 학생 정보를 수정합니다 ");

	int id = ioh.getInteger(" 수정할 학생의 학번을 입력하시오 : ");
	ioh.putString(" 다음 학생의 정보를 수정합니다 ");

	Student s = ioh.getStudent();
	s_list.updateStudent(findStudent(s_list, id), s); // 검색 후 지정된 id의 정보를 기준으로 생성자를 삽입하는 함수를 호출
}
void editStudentList(StudentList& list1) //See project description, also looking the main() will help you
{
    string command;

    cout << "*******Student Registration System*******" << endl;

    for(;;)
    {
        cout << "Enter a command: " << endl; //Command prompt
        cin >> command;



        if(command == PrintWrtId)
        {   //ofstream os;
            //os.open("Filename")
            list1.printwrtID();//list1.printwrtID(os);
            //os.close();
            cout << "done printing w.r.t id" << endl;
        }
        else if(command == DeleteStudent)
        {
            int given=0;
again:
            try //if anything wrong occurs, we have to "handle" it
            {
                cout<<"Enter ID:";
                cin>>given;
                cout<< "read" << endl;
            }
            catch(...) //catching local exceptions
            {
                cout<<"except"<<endl;
                goto again;
            }
            list1.removefromlist(given);
        }
        else if (command == Quit)
int createStudentList(StudentList& list1,int amount) //see project description for further info
{
    if(amount==0) cout << "It's not logical to add  0 members to the list, is it?" << endl;
    else {
        srand (time(NULL));
        for(int i=0; i<amount; i++)
        {
            StudentNode* std=new StudentNode("RANDOM");
            list1.addStudent2list(std); //see addstudent2list description for further info
        }
        cout << "Random List Creation Ended Successfully!" << endl;
        return 1;
    }
    return 0;
}
int createStudentList(string filename, StudentList& list1) //See project description for further info
{
    ifstream txtread;
    txtread.open(filename);
    if(!txtread) //controlling whether it's working or not
    {
        cout << "Cannot open/read file" << endl;
        return -1;
    }
    cout << "File is open" << endl;
    while(!txtread.eof()) //Read Until EOF
    {
        StudentNode* std=new StudentNode(txtread);
        list1.addStudent2list(std); //see addstudent2list description for further info
    }
    system("PAUSE");
    return 0;
}
예제 #12
0
void FileHandler::saveStudent(string fileName, StudentList& s_list) // 파일 쓰기용
{
	ofstream fout;

	fout.open(fileName, ios_base::out);

	for (int i = 0; i < s_list.getCount(); i++)
	{
		fout << s_list.getStudentList(i).getId() << "\t";
		fout << s_list.getStudentList(i).getName() << "\t";
		fout << s_list.getStudentList(i).getKor() << "\t";
		fout << s_list.getStudentList(i).getMath() << "\t";
		fout << s_list.getStudentList(i).getEng() << "\t";
		fout << s_list.getStudentList(i).getAvgRecord() << "\t";
		fout << endl;
	}

	fout.close();
}
예제 #13
0
void FileHandler::loadStudent(string fileName, StudentList& s_list) // 파일 읽기용
{
	ifstream fin;
	fin.open(fileName, ios_base::in);

	int id;
	string name;
	int kor;
	int eng;
	int math;

	while (!fin.eof()) // 파일의 끝에 도달하지 않았다면 계속 반복
	{
		fin >> id >> name >> kor >> eng >> math; // 파일의 값을 읽음
		Student s(id, name, kor, eng, math); // Student 임시 객체 생성

		s_list.insertStudent(s);
	}

	fin.close();
}
예제 #14
0
int main()
{
	int index = -1;
	//List of data
	FacultyList facultylist;
	StaffList stafflist;
	StudentList studentlist;
	do
	{
		//Print Menu
		cout<<"0. 구성원 파일 로드"<<endl;
		cout<<"1. 전체 구성원 조회"<<endl;
		cout<<"2. 학과(부서) 구성원 조회"<<endl;
		cout<<"3. 이름으로 검색"<<endl;
		cout<<"4. ID로 검색"<<endl;
		cout<<"5. 구성원 추가"<<endl;
		cout<<"6. 구성원 정보 수정"<<endl;
		cout<<"7. 구성원 정보 삭제"<<endl;
		cout<<"8. 구성원 목록 저장"<<endl;
		cout<<"9. 프로그램 종료"<<endl;
		cout<<">>";
		cin>>index;
		
		switch(index)
		{
		case 0:
			{
				string filename, name, id, dept, position, mail;
				char inputstring[BUFFERSIZE], *ptr;
				int party = 0, people = 0;

				//Input
				cout<<"파일 이름 입력 : ";
				cin>>filename;

				//File open
				ifstream infile(filename.c_str(), ios::in);
				if(!infile)
				{
					cout<<"파일이 존재하지 않습니다!"<<endl;
					break;
				}

				//Init Lists
				facultylist.RemoveAll();
				stafflist.RemoveAll();
				studentlist.RemoveAll();

				//Parsing
				while(infile.getline(inputstring, BUFFERSIZE-1))
				{	
					//To remove carrage return caracter in linux
					if(strlen(inputstring)>0 && inputstring[strlen(inputstring)-1]=='\r')
						inputstring[strlen(inputstring)-1]=0;
					if(strcmp(inputstring,"-교원")==0)
					{
						party = FACULTY;
						continue;
					}
					else if(strcmp(inputstring,"-직원")==0)
					{
						party = STAFF;
						continue;
					}
					else if(strcmp(inputstring,"-학생")==0)
					{
						party = STUDENT;
						continue;
					}
					else
					{
						//Parsing Data & Copy
						ptr = strtok(inputstring," ");
						name.assign(ptr);
						ptr = strtok(NULL," ");
						id.assign(ptr);
						ptr = strtok(NULL," ");
						dept.assign(ptr);
						ptr = strtok(NULL," ");
						position.assign(ptr);
						ptr = strtok(NULL," ");
						mail.assign(ptr);
						if(party == FACULTY)
							facultylist.Add(id, name, dept, position, mail);
						else if (party == STAFF)
							stafflist.Add(id, name, dept, position, mail);
						else if(party == STUDENT)
							studentlist.Add(id, name, dept, position, mail);
						people++;
					}

				}
				//print Results
				cout<<people<<"명의 정보를 로드하였습니다!"<<endl;
				infile.close();
			}
			break;
		case 1:
			//query entire member
			facultylist.InquireAll();
			cout<<endl;
			stafflist.InquireAll();
			cout<<endl;
			studentlist.InquireAll();
			break;
		case 2:
			//Search by dept name
			{
				string dept;
				int people = 0;
				cout<<"학과(부서) 입력 : ";
				cin>>dept;
				people = facultylist.InquireByDept(dept);
				people += stafflist.InquireByDept(dept);
				people += studentlist.InquireByDept(dept);
				if(people==0) cout<<"해당 학과(부서)의 사람이 존재하지 않습니다!"<<endl;
			}
			break;
		case 3:
			//Search by name
			{
				string name;
				int people = 0;
				cout<<"이름 입력 : ";
				cin>>name;
				people = facultylist.InquireByName(name);
				people += stafflist.InquireByName(name);
				people += studentlist.InquireByName(name);
				if(people==0)
					cout<<"해당 이름의 사람이 존재하지 않습니다!"<<endl;
			}
			break;
		case 4:
			//Search by id
			{
				string id;
				int people = 0;
				cout<<"ID 입력 : ";
				cin>>id;
				people = facultylist.InquireByID(id);
				people += stafflist.InquireByID(id);
				people += studentlist.InquireByID(id);
				if(people==0)
					cout<<"해당 ID의 사람이 존재하지 않습니다!"<<endl;
			}
			break;
		case 5:
			//Add member data
			{
				int party;
				string  id, name, dept, position, mail;
				cout<<"구성원 소속 선택(1.교수 2.직원 3.학생): ";
				cin>>party;
				cout<<"ID 입력: ";
				cin>>id;
				cout<<"이름 입력: ";
				cin>>name;
				cout<<"학과(부서) 입력: ";
				cin>>dept;
				cout<<"직급 입력: ";
				cin>>position;
				cout<<"메일 입력: ";
				cin>>mail;
				if(party == FACULTY)
				{
					if(!facultylist.Add(id, name, dept, position, mail))
						cout<<"이미 같은 ID가 존재합니다!"<<endl;
				}
				else if(party == STAFF)
				{
					if(!stafflist.Add(id, name, dept, position, mail))
						cout<<"이미 같은 ID가 존재합니다!"<<endl;
				}
				else if(party == STUDENT)
				{
					if(!studentlist.Add(id, name, dept, position, mail))
						cout<<"이미 같은 ID가 존재합니다!"<<endl;
				}
				else
				{
					cout<<"잘못된 소속입니다!"<<endl;
				}
			}
			break;
		case 6:
			//Modify member data
			{
				string  id, name, dept, position, mail;
				cout<<"ID 입력: ";
				cin>>id;
				cout<<"이름 입력: ";
				cin>>name;
				cout<<"학과(부서) 입력: ";
				cin>>dept;
				cout<<"직급 입력: ";
				cin>>position;
				cout<<"메일 입력: ";
				cin>>mail;
				if(facultylist.Modify(id, name, dept, position, mail))
					cout<<"수정 완료!"<<endl;
				else if(stafflist.Modify(id, name, dept, position, mail))
					cout<<"수정 완료!"<<endl;
				else if(studentlist.Modify(id, name, dept, position, mail))
					cout<<"수정 완료!"<<endl;
				else
					cout<<"일치하는 ID를 찾을 수 없습니다"<<endl;
			}
			break;
		case 7:
			//delete member data
			{
				string id;
				cout<<"ID 입력: ";
				cin>>id;
				if(facultylist.Delete(id))
					cout<<"삭제 완료!"<<endl;
				else if(stafflist.Delete(id))
					cout<<"삭제 완료!"<<endl;
				else if(studentlist.Delete(id))
					cout<<"삭제 완료!"<<endl;
				else
					cout<<"일치하는 ID를 찾을 수 없습니다"<<endl;
				
			}
			break;
		case 8:
			//saving to file
			{
				string filename;
				cout<<"파일 이름 입력: ";
				cin>>filename;
				ofstream outfile(filename.c_str());
				if(!outfile)
				{
					cout<<"File Open Error"<<endl;
					break;
				}
				outfile<<"-교원"<<endl;
				facultylist.SaveFile(outfile);
				outfile<<"-직원"<<endl;
				stafflist.SaveFile(outfile);
				outfile<<"-학생"<<endl;
				studentlist.SaveFile(outfile);
				cout<<"저장 완료!"<<endl;
				outfile.close();
			}
			break;
		case 9:
			break;
		default:
			{
				//Wrong input
				cout<<"잘못된 입력입니다!"<<endl;
			}
			break;
		}
		cout<<endl;
	}while(index!=9);
	return 0;
}