Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <iomanip>
- using namespace std;
- struct ksiazka {
- char autor[30], tytul[50];
- int rokWydania, liczbaStron;
- double cena;
- char wypozyczona;
- int ileWypozyczen;
- ksiazka() {
- }
- ksiazka(char *autor, char *tytul, int rokWydania, int liczbaStron, double cena, char wypozyczona, int ileWypozyczen) {
- int autorlength = strlen(autor);
- for (int i = 0; i < autorlength; i++) {
- this->autor[i] = autor[i];
- }
- this->autor[autorlength] = '\0';
- for (int i = 0; i <= strlen(tytul); i++) {
- this->tytul[i] = tytul[i];
- }
- this->rokWydania = rokWydania;
- this->liczbaStron = liczbaStron;
- this->cena = cena;
- this->wypozyczona = wypozyczona;
- this->ileWypozyczen = ileWypozyczen;
- }
- void print() {
- cout << autor << endl;
- cout << tytul << endl;
- cout << rokWydania << endl;
- cout << liczbaStron << endl;
- cout << cena << endl;
- cout << wypozyczona << endl;
- cout << ileWypozyczen << endl;
- }
- static ksiazka wczytaj() {
- char autor[30], tytul[50];
- int rokWydania, liczbaStron;
- double cena;
- char wypozyczona;
- int ileWypozyczen;
- bool poprawne = true;
- do {
- poprawne = true;
- cout << "podaj autora: ";
- cin >> setw(30) >> autor;
- for (int i = 0;i < strlen(autor);i++) {
- if (((autor[i] >= 'A' && autor[i] <= 'Z') ||
- (autor[i] >= 'a' && autor[i] <= 'z')) == false)
- poprawne = false;
- }
- } while (poprawne == false);
- while (true)
- {
- cout << "podaj tytul: ";
- cin >> setw(50) >> tytul;
- bool poprawny = true;
- for (int i = 0; i < strlen(tytul); i++)
- {
- /*if (((autor[i] >= 'A' && autor[i] <= 'Z') ||
- (autor[i] >= 'a' && autor[i] <= 'z') ||
- (autor[i] >= '0' && autor[i] <= '9')) == false)*/
- if ((autor[i] < 'A' && autor[i] > 'Z') && (autor[i] < 'a' && autor[i] > 'z') && (autor[i] < '0' && autor[i] > '9'))
- {
- poprawne = false;
- break;
- }
- }
- if (poprawny)
- break;
- }
- while (true) {
- cout << "podaj rok wydania Cyko: ";
- cin >> rokWydania;
- if (rokWydania <= 2017 && rokWydania > 0)
- break;
- }
- while (true) {
- cout << "podaj liczbe stron: ";
- cin >> liczbaStron;
- if (liczbaStron > 0)
- break;
- }
- while (true) {
- cout << "podaj cene: ";
- cin >> cena;
- if (cena >= 0)
- break;
- }
- while (true) {
- cout << "czy jest wypozyczona? ";
- cin >> wypozyczona;
- if (wypozyczona == 'T' || wypozyczona == 'N')
- break;
- }
- while (true) {
- cout << "ile razy zostala wypozyczona? ";
- cin >> ileWypozyczen;
- if (ileWypozyczen >= 0)
- break;
- }
- return ksiazka(autor, tytul, rokWydania, liczbaStron, cena, wypozyczona, ileWypozyczen);
- }
- };
- void dodajksiazki(const int n, ksiazka *ksiazki) {
- for (int i = 0;i < n;i++) {
- ksiazki[i] = ksiazka::wczytaj();
- }
- }
- int main() {
- /*char autor[30], tytul[50];
- int rokWydania, liczbaStron;
- double cena;
- char wypozyczona;
- int ileWypozyczen;
- cin >> setw(30) >> autor;
- cin >> setw(50) >> tytul;
- cin >> rokWydania;
- cin >> liczbaStron;
- cin >> cena;
- cin >> wypozyczona;
- cin >> ileWypozyczen;*/
- const int n = 2;
- ksiazka ksiazki[n];
- dodajksiazki(n, ksiazki);
- for (int i = 0;i < n;i++) {
- ksiazki[i].print();
- }
- ///*ksiazka sexy = ksiazka::wczytaj();*/
- //sexy.print();
- while (true);
- }
Add Comment
Please, Sign In to add comment