R
R
Reslyukov Alexander2021-06-25 15:27:14
C++ / C#
Reslyukov Alexander, 2021-06-25 15:27:14

How to solve the following two problems?

In the program, you can drive variables of three classes into the database - Librarian, Reader and Order.
After you can display a list of entered.
Problems are. Firstly, if you enter two words through the problems when entering, then the second word will be read into the next variable, which is why, for example, three words cannot be entered in PIB - full name. Or, you cannot enter a complete address in the address.
Secondly, if you enter several "pieces" into the database, for example, readers, then the program returns to the menu, re-enter a few more readers, then the last ones entered will replace the first ones and only the last ones will be displayed in the list.
These are the two problems I don't know how to fix.

#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; 
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Ananiev, 2021-06-25
@Alexandr_202

1. Use cin.getline https://stackoverflow.com/questions/5838711/stdcin...
2. When you add new readers, the cycle starts from 0 , but you need to start from the number of readers already added (here you need to take into account that there was no array overflow, i.e. totalReaderCnt + Reader_kol must be less than 500)
for (int i = 0; i < Reader_kol; i++)

for (int i = totalReaderCnt; i < totalReaderCnt + Reader_kol; i++)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question