Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include "stdafx.h"
- #include<iostream>
- #include<fstream>
- #include<conio.h>
- #include<string.h>
- #include<vector>
- #define SIZE 256
- using namespace std;
- double sum = 0;
- int time = 0;
- class City
- {
- protected:
- char* name;
- char* date;
- char* code;
- char* phoneSubs;
- char* phone;
- private:
- virtual void printInfo() = 0;
- };
- class Call
- {
- protected:
- int duration;
- double tariff;
- };
- class Info: public City, Call
- {
- public:
- Info();
- void set(char*, char*, char*, char*, char*, int, double);
- void run();
- void printInfo();
- void printSumary();
- void filePrintCityInfo();
- void filePrintCitySummary();
- void fileShowInfo();
- void fileDelte();
- };
- Info::Info()
- {
- name = new char [SIZE];
- code = new char [SIZE];
- phoneSubs = new char [SIZE];
- phone = new char [SIZE];
- date = new char [SIZE];
- };
- void Info::set(char* name_, char* code_, char* phoneSubs_, char* phone_, char* date_, int duration_, double tariff_)
- {
- strcpy(name, name_);
- strcpy(code, code_);
- strcpy(phoneSubs, phoneSubs_);
- strcpy(phone, phone_);
- strcpy(date, date_);
- duration = duration_;
- tariff = tariff_;
- };
- void Info::run()
- {
- time += duration;
- sum += (duration * tariff);
- };
- void Info::printInfo()
- {
- cout<<"_____City__Info_____"<<endl;
- cout<<"Name: "<<name<<endl;
- cout<<"Code: "<<code<<endl;
- cout<<"Subscriber's phone number: "<<phoneSubs<<endl;
- cout<<"Destination phone number: "<<phone<<endl;
- cout<<"Date of a call: "<<date<<endl;
- cout<<"Duration of a call: "<<duration<<endl;
- cout<<"Tariff of a call: "<<tariff<<endl;
- cout<<"____________________"<<endl;
- };
- void Info::printSumary()
- {
- cout<<"_____City__Summary__"<<endl;
- cout<<"Total duration: "<<time<<endl;
- cout<<"Total value: "<<sum<<endl;
- cout<<"____________________"<<endl;
- };
- void Info::filePrintCityInfo()
- {
- ofstream file("cityInfo.txt", ios::app);
- file<<name<<" "<<code<<" "<<phoneSubs<<" "<<phone<<" "<<date<<" "<<duration<<" "<<tariff<<endl;
- file.close();
- };
- void Info::filePrintCitySummary()
- {
- ofstream file("cityInfo.txt", ios::app);
- file<<endl<<name<<" "<<time<<" "<<sum<<endl;
- file.close();
- };
- void Info::fileShowInfo()
- {
- try
- {
- char word[160];
- ifstream fileout("cityInfo.txt", ios::_Nocreate);
- if (fileout.fail())
- {
- throw 4;
- }
- cout<<"Summary city info: "<<endl;
- cout<<"--------------------------------------------"<<endl;
- while ( !fileout.eof() )
- {
- fileout.getline(word,159);
- cout<<word<<endl;
- }
- cout<<endl;
- fileout.close();
- }
- catch (int x)
- {
- cout<<"Requesting file dose not exist or have enother name! ERROR "<<x<<endl;
- }
- system("pause");
- };
- void Info::fileDelte()
- {
- try
- {
- ifstream fileout("cityInfo.txt", ios::_Nocreate);
- if (fileout.fail())
- {
- throw 4;
- }
- else
- {
- fileout.close();
- remove("cityInfo.txt");
- cout<<"Requires file deleted"<<endl;
- }
- }
- catch (int x)
- {
- cout<<"Requesting file dose not exist or have enother name! ERROR "<<x<<endl;
- }
- system("pause");
- };
- int menu()
- {
- system("cls");
- cout<<endl;
- cout<<"1. Add city & city info"<<endl;
- cout<<"2. Output city info"<<endl;
- cout<<"3. Output city summary"<<endl;
- cout<<"4. Write summary info to file"<<endl;
- cout<<"5. Print info from file"<<endl;
- cout<<"6. Delete info file"<<endl;
- cout<<"0. Exit"<<endl<<endl;;
- int item;
- cin>>item;
- return item;
- }
- int main()
- {
- Info one;
- char name_[64];
- char code_[8];
- char phoneSubs_[16];
- char phone_[16];
- char date_[16];
- int duration_;
- double tariff_;
- int chose = menu();
- while (chose)
- {
- switch (chose)
- {
- case 1:
- cout<<"Input name, code, phoneSubs, phone, date, duration, tariff: "<<endl;
- cin>>name_;
- //-----
- l1: try
- {
- char codeTry[8];
- cin>>codeTry;
- if (strlen(codeTry) != 5)
- {
- throw 1;
- }
- else (strcpy(code_, codeTry));
- }
- catch (int x) {cout<<"Incorrect phone code! ERROR "<<x<<endl<<"Try again..."<<endl; goto l1;}
- //-----
- l2: try
- {
- char phoneSubsTry[16];
- cin>>phoneSubsTry;
- if (strlen(phoneSubsTry) != 7)
- {
- throw 2;
- }
- else (strcpy(phoneSubs_, phoneSubsTry));
- }
- catch (int x) {cout<<"Incorrect phoneSubs number! ERROR "<<x<<endl<<"Try again..."<<endl; goto l2;}
- //-----
- l3: try
- {
- char phoneTry[16];
- cin>>phoneTry;
- if (strlen(phoneTry) != 7)
- {
- throw 3;
- }
- else (strcpy(phone_, phoneTry));
- }
- catch (int x) {cout<<"Incorrect phone number! ERROR "<<x<<endl<<"Try again..."<<endl; goto l3;}
- //-----
- cin>>date_;
- cin>>duration_;
- cin>>tariff_;
- one.set(name_, code_, phoneSubs_, phone_, date_, duration_, tariff_);
- one.run();
- one.filePrintCityInfo();
- system("pause");
- break;
- case 2:
- one.printInfo();
- system("pause");
- break;
- case 3:
- one.printSumary();
- system("pause");
- break;
- case 4:
- one.filePrintCitySummary();
- break;
- case 5:
- one.fileShowInfo();
- break;
- case 6:
- one.fileDelte();
- break;
- case 0:
- return 0;
- break;
- }
- chose = menu();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement