Manh Pham

@ngocmanh_cntt3

Viet Nam, Ha Noi

Joined Oct 2016

World Rank: #34112 (0.7 points)

Institution: Ha Noi university of industry

#include<iostream> #include <memory> #include <list> #include <string> #include <iomanip> using namespace std; class Person { public: string name; string address; int year_born; int type; // Teacher=9, Student=6 Person() { } }; list<Person*> total_list; class Student : public Person { public: int id; string mother_name; Student() { } void update() { cout << "ten me sau khi cap nhat:"; cin >> mother_name; } }; class Teacher : public Person { public: string subject; Teacher() { } }; int mainmenu() { int choice; cout << "Menu: " << endl; cout << " 1. Them sinh vien" << endl; cout << " 2. Them giao vien" << endl; cout << " 3. Xoa 1 sinh vien" << endl; cout << " 4. Cap nhat ten me sinh vien" << endl; cout << " 5. In thong tin sinh vien" << endl; cout << " 6. In danh sach sinh vien va giao vien" << endl; cout << " Lua chon: (0 de thoat) "; cin >> choice; return choice; } //void print_with_len(string str, int len, char eend) //{ // cout << str; // // for (int i = 1; i <= len - str.size(); i++) cout << " "; // cout << end; //} void add_student() { Student *st = new Student(); st->type = 6; cout << "Nhap ten sv: "; cin >> st->name; fflush(stdin); cout << "Dia chi: "; cin >> st->address; fflush(stdin); cout << "Nam sinh: "; cin >> st->year_born; fflush(stdin); cout << "MSSV: "; cin >> st->id; fflush(stdin); cout << "Ten me: "; cin >> st->mother_name; fflush(stdin); total_list.push_back(st); } void add_teacher() { Teacher *tc = new Teacher(); tc->type = 9; cout << "Nhap ten gv: "; cin >> tc->name; fflush(stdin); cout << "Dia chi: "; cin >> tc->address; fflush(stdin); cout << "Nam sinh: "; cin >> tc->year_born; fflush(stdin); cout << "Mon: "; cin >> tc->subject; total_list.push_back(tc); } void remove_st() { int id; cout << "\nNhap id sinh vien can xoa: "; cin >> id; fflush(stdin); for (std::list<Person*>::iterator it=total_list.begin(); it != total_list.end(); ++it) { Person *per = *it; Student *st = static_cast<Student*>(per); if (st->type == 1) continue; if (st->id != id) continue; total_list.remove(*it); return; } } void update_mother_name() { int id; cout << "\nNhap id sinh vien can cap nhat ten me"; cin >> id; fflush(stdin); for (list<Person*>::iterator it=total_list.begin(); it != total_list.end(); ++it) { Person *per = *it; Student *st = static_cast<Student*>(per); if (st->type == 1) continue; if (st->id != id) continue; cout << "Nhap ten me: "; cin >> st->mother_name; //per = st; cout<< "done!!"; return; } } void show_st_id() { int id; cout << "\nNhap id sinh vien can xem: "; cin >> id; fflush(stdin); for (list<Person*>::iterator it=total_list.begin(); it != total_list.end(); ++it) { Person *per = *it; Student *st = static_cast<Student*>(per); if (st->id == id) { // printf("\n%-15s%-20s%-10s%-5s%-15s", "Ho ten", "Dia chi", "Nam sinh", "ID", "Ho ten me"); // printf("\n%-15s%-20s%-10d%-5d%-15s", st->name, st->address, st->year_born, st->id, st->mother_name); cout << st->name << " " << st->address << " " << st-> year_born << " " << st->id << " " << st->mother_name << endl; return; } // return; } cout << "\nkhong tim thay!!"; } void show_all() { printf("\n%-15s%-20s%-10s%-15s", "Ho ten", "Dia chi", "Nam sinh", "Loai"); //printf("%15s %10") for (list<Person*>::iterator it=total_list.begin(); it != total_list.end(); ++it) { Person *per = *it; //print_with_len(per->name, 20, ' '); string name = per->name; string add = per->address; int year = per->year_born; cout << "\n"<<name << " " << add << " " << year << (per->type == 6 ? "Hoc sinh": "Giao vien") <<"\n"; //printf("\n%s%s%d", name,add, year); //cout << (per->type == 6 ? "Hoc sinh": "Giao vien"); //print_with_len(per->address, 20, ' '); } } int main() { int choice; while(1) { choice = mainmenu(); if (!choice) break; switch(choice) { case 1: add_student(); break; case 2: add_teacher(); break; case 3: remove_st(); break; case 4: update_mother_name(); break; case 5: show_st_id(); break; case 6: show_all(); break; default: break; } } //printf("\n%-15s%-20s%-10s%-15s", "Ho ten", "Dia chi", "Nam sinh", "Loai"); //printf("\n%-15s%-20s%-10d%-15s", "manh ne", "11111 a", 1997, "Hoc sinh"); return 0; } hihi

Activity over the last year

Effectiveness

 Problems solved
20
 Solutions submitted
240

Problems