Как решить две следующие проблемы?

В программе можно вбивать в базу переменные трех классов - Библиотекаря, Читателя и Заказа.
После можно выводить список введенного.
Проблемы такие. Во-первых, если при вводе ввести два слова через проблем, то второе слово зачитается уже в следующую переменную, из-за чего например в PIB нельзя ввести три слова - ФИО. Или в адресе нельзя ввести полный адрес.
Во-вторых, если ввести в базу, например читателей, несколько "штук", затем программа вернется в меню, вновь ввести еще несколько читателей, то последние введенные заменят первые и в списке будут отображаться только последние.
Вот эти две проблемы не знаю, как исправить.
#include <iostream>
#include <string>
#include <windows.h>
using namespace std;

class Bibl {
private: 
	string Bibl_name, PIB, adres, otdel; int nomer; 
public:
	void Add_Bibl(string a, string b, string c, int d, int e) {
		Bibl_name = a;
		PIB = b;
		adres = c;
		nomer = d;
		otdel = e;
	}
	void GetBibl() {
		cout << "Librarian name: \t" << Bibl_name << endl << "Full name: \t" << PIB << endl << "Address: \t" << adres << endl << "Phone number: \t" << nomer << endl << "The Department: " << otdel << endl;
		} 
	} ;

class Reader {
private:
	string Bibl_name_r, PIB_r; int nomer_r, zakaz;
public:
	void Add_Reader(string f, string g, int h, int j) {
		Bibl_name_r = f;
		PIB_r = g;
		nomer_r = h;
		zakaz = j;
	}
	void GetReader() {
		cout << "Librarian name: \t" << Bibl_name_r << endl << "Full name: \t" << PIB_r << endl << "Phone number: \t" << nomer_r << endl << "Order number: \t" << zakaz << endl;
	}
} ;

class Order {
private:
	string book, autor, time1, time2; int year;
public:
	void Add_Order(string k, string l, string m, string n, int o) {
		book = k;
		autor = l;
		time1 = m;
		time2 = n;
		year = o;
	}
	void GetOrder() {
		cout << "Book name: \t" << book << endl << "Autor name: \t" << autor << endl << "Year of issue: \t" << year << endl << "Delivery time to the client: \t" << time1 << endl << "Hold time: " << time2 << endl;
	}
} ;


int main() {
	string a, b, c; int e, d;
	string f, g; int h, j;
	string k, l, m, n; int o;
	bool soft = true;
	short menu, Bibl_kol, Reader_kol, Order_kol;
	Bibl Binfo[500];
	Reader Rinfo[500];
	Order Oinfo[500];
while (soft == true) {
	system ("cls");
	cout << "\t 1) Dobavit bibliotekar" << endl << "\t 2) Dobavit chitatel" << endl << "\t 3) Dobavit zakaz" << endl << "\t 4) Spisok bibl" << endl << "\t 5) Spisok reader" << endl << "\t 6) Spisok zakazov" << endl;
	cin >> menu;

	if (menu == 1) {
		system ("cls");
		cout << ("Skolko bibliotekar dobavit? "); cin >> Bibl_kol;
		for (int i = 0; i < Bibl_kol; i++) {
				system ("cls");

				cout << "Librarian name: "; cin >> a, cout << endl;
				cout << "Full name: "; cin >> b; cout << endl;
				cout << "Address: "; cin >> c; cout << endl;
				cout << "Phone number: "; cin >> d; cout << endl;
				cout << "The Department: "; cin >> e; cout << endl;
				Binfo[i].Add_Bibl(a, b, c, d, e);
			}
			cout << "Dobavleno." << endl;
			Sleep (3000);
	}
	if (menu == 2) {
		system ("cls");
		cout << ("Skolko reader dobavit? "); cin >> Reader_kol;
		for (int i = 0; i < Reader_kol; i++) {
				system ("cls");

				cout << "Librarian name: "; cin >> f, cout << endl;
				cout << "Full name: "; cin >> g; cout << endl;
				cout << "Phone number: "; cin >> h; cout << endl;
				cout << "Order name: "; cin >> j; cout << endl;
				Rinfo[i].Add_Reader(f, g, h, j);
			}
			cout << "Dobavleno." << endl;
			Sleep (3000);
	}
	if (menu == 3) {
		system ("cls");
		cout << ("Skolko zakazov dobavit? "); cin >> Order_kol;
		for (int i = 0; i < Order_kol; i++) {
				system ("cls");

				cout << "Book name: "; cin >> k, cout << endl;
				cout << "Autor name: "; cin >> l; cout << endl;
				cout << "Delivery time to the client: "; cin >> m; cout << endl;
				cout << "Hold time: "; cin >> n, cout << endl;
				cout << "Year of issue: "; cin >> o; cout << endl;
				Oinfo[i].Add_Order(k, l, m, n, o);
			}
			cout << "Dobavleno." << endl;
			Sleep (3000);
	}
	if (menu == 4) { 
         	system ("cls");
         	for (int i = 0; i < Bibl_kol; i++) {
         		Binfo[i].GetBibl();
         		Sleep(1000);
         	}
         	Sleep (3000);
         }
    if (menu == 5) { 
         	system ("cls");
         	for (int i = 0; i < Reader_kol; i++) {
         		Rinfo[i].GetReader();
         		Sleep(1000);
         	}
         	Sleep (3000);
         }
    if (menu == 6) { 
         	system ("cls");
         	for (int i = 0; i < Order_kol; i++) {
         		Oinfo[i].GetOrder();
         		Sleep(1000);
         	}
         	Sleep (3000);
         }
    }
return 0; 
}
  • Вопрос задан
  • 92 просмотра
Решения вопроса 1
1. Использовать cin.getline https://stackoverflow.com/questions/5838711/stdcin...
2. У вас при добавлении новых читателей цикл стартует с 0
for (int i = 0; i < Reader_kol; i++)
а надо, чтобы стартовал с количества уже добавленных читателей (тут надо учитывать, чтобы не было переполнения массива, т.е. totalReaderCnt + Reader_kol должно быть меньше 500)
for (int i = totalReaderCnt; i < totalReaderCnt + Reader_kol; i++)
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы