You are on page 1of 2

#include<iostream>

#include<string>
#include<cstdlib>
#include<iomanip>
using namespace std;

struct van_phong
{
string ten;
long int sdt;
string chu_de;
double phi;
};
void nhap_du_lieu(van_phong a[], int size)
{
system("cls");
for (int i = 0; i < size; i++)
{
cout << "moi ban nhap du lieu cho tac gia so " << i + 1 << endl;;
cout << "moi ban nhap ten : "; cin.ignore(); getline(cin, a[i].ten);
cout << "moi ban nhap so dien thoai : "; cin >> a[i].sdt;
cout << "moi ban nhap chu de : "; cin.ignore(); getline(cin,
a[i].chu_de);
cout << "moi ban nhap phi bat buoc : "; cin >> a[i].phi;
system("cls");
}
}
void hien_thi(van_phong b[], int size)
{
system("cls");
cout << setw(17) << left << "ten dien gia" << setw(15) << right << "so dien
thoai"
<< setw(23) << right << "chu de dien thuyet" << setw(17) << right <<
"phi bat buoc\n";
for(int o=0;o<size;o++)
{
cout << b[o].ten << setw(19) << right << b[o].sdt <<
setw(23) << right << b[o].chu_de << setw(15) << right << b[o].phi
<< endl;
}
}
void thay_doi(van_phong c[],int size)
{

system("cls");
cout << setw(16) << left << " ten dien gia" << setw(15) << right << "so dien
thoai"
<< setw(23) << right << "chu de dien thuyet" << setw(17) << right <<
"phi bat buoc\n";
for (int m = 0; m < size; m++)
{
cout<< m+1 <<"." << c[m].ten << setw(21) << right << c[m].sdt <<
setw(23) << right << c[m].chu_de << setw(15) << right << c[m].phi
<< endl;
}
cout <<
"----------------------------------------------------------------------\n";
int n, a;
cout << "chon nguoi can thay doi : ";
cin >> n;
tryAgain:
cout<<"1.thay doi ten\n" << "2.thay so dien thoai\n";
cout << "3.chu de dien thuyet\n"; cout << "4.phi bat buoc\n";
cout << "0.de quay lai\n";
cout << "chon du lieu can thay doi : ";
cin >> a;
switch(a)
{
case 1:
cout << "nhap ten moi : "; cin.ignore();
getline(cin, c[n].ten);
goto tryAgain;
case 2:
cout << "nhap so dien thoat moi : ";
cin >> c[n].sdt;
goto tryAgain;
case 3:
cout << "nhap chu de moi : "; cin.ignore();
getline(cin, c[n].chu_de);
goto tryAgain;
case 4:
cout << "nhap muc phi moi : ";
cin >> c[n].phi;
goto tryAgain;
default:
break;
}
}
int main()
{
int n;
van_phong* ptr = nullptr;
ptr = new van_phong[1];
tryAgain:
cout << " 1.nhap du lieu vao mang\n" << " 2.thay doi du lieu trong mang\n"
<< " 3.hien thi tat ca du lieu trong mang\n" << " 4.thoat khoi chuong
trinh\n";
cout << "-------------------------------\n";
cout << "moi ban chon yeu cau : ";
cin >> n;
switch(n)
{
case 1:
nhap_du_lieu(ptr,1);
goto tryAgain;
case 2:
thay_doi(ptr, 1);
goto tryAgain;
case 3:
hien_thi(ptr, 1);
goto tryAgain;
default:
return 0;
}
system("pause");
}

You might also like