Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "bus.h"
- #include "functions.h"
- #include <string>
- #include <iostream>
- #include<fstream>
- int SIZE = 50;
- using namespace std;
- int main() {
- fstream inFile;
- string input;
- string temp;
- int i = 0;
- Bus * busArray[SIZE];
- for (int i = 0; i < SIZE; i++){
- busArray[i] = nullptr;
- }
- inFile.open("C:\\Users\\Mohammad\\Documents\\CS200\\Eclipse Workspace\\KhanA4\\src\\a4data.txt");
- if(inFile.fail()){
- cout << "Unsuccessful to open file" << endl;
- return -1;
- }
- //setArray(busArray, inFile);
- getline(inFile,temp);
- while(!inFile.eof()){
- busArray[i] = new Bus(temp.substr(0,5), temp.substr(5,10),stoi(temp.substr(15,3)),stoi(temp.substr(18,7)),temp.c_str()[25]);
- i++;
- getline(inFile,temp);
- }
- display(busArray);
- do{
- cout << "Enter A Transaction Code(D = display, L = list a bus, C=change, X=exit)";
- cin >> input;
- cout << input << endl;
- if(input.c_str()[0]== 'D'){
- display(busArray);
- }
- else if(input.c_str()[0] == 'L'){
- listt(busArray,input);
- }
- else if(input.c_str()[0] == 'C'){
- change(busArray,input);
- }
- cout << "Enter transaction code (D = display, L = list a bus, C=change, X=exit \n)";
- getline(cin,input);
- }while(input.c_str()[0] != 'X');
- for(int i = 0; i<SIZE; i++){
- delete busArray[i];
- }
- cout << "Thank you and have a nice day!" << endl;
- inFile.close();
- return 0;
- }
- #include "functions.h"
- void listt(Bus* array[],string x){
- int i =0;
- int y = 0;
- while( array[i] != nullptr){
- if(array[i]->getBusID() == x.substr(2,5)){
- cout << "=======================================================================\n";
- cout << "BUS ID\t\t" << "BUS MANUFACTURER\t" << "BUS CAPACITY\t" << "MILEAGE\t" <<setw(5) <<"Status" << endl;
- cout << "=======================================================================\n";
- cout << array[i]->getBusID() << "\t\t" << array[i]->getmanufacturer()
- << "\t\t" <<setw(5) <<array[i]->getCapacity() << "\t\t"<<array[i]-> getMileage() << "\t" << setw(5) <<array[i]->getStatus() << '\n';
- cout << "---end of list---" << endl;
- y++;
- }
- i++;
- }
- if(y <= 0){
- cout << "Not Found" << endl;
- }
- }
- void change(Bus* array[],string x){
- int i = 0;
- int y = 0;
- while(array[i] != nullptr){
- if(array[i]->getBusID() == x.substr(2,5)){
- cout << "Change successful!" << endl;
- array[i]->setStatus(x.c_str()[8]);
- y++;
- }
- i++;
- }
- if(y <= 0){
- cout <<"not Found" << endl;
- }
- }
- void display(Bus * array[]){
- int i = 0;
- cout << "=======================================================================\n";
- cout << "BUS ID\t\t" << "BUS MANUFACTURER\t" << "BUS CAPACITY\t" << "MILEAGE\t" <<setw(5) <<"Status" << endl;
- cout << "=======================================================================\n";
- while(array[i] != nullptr){
- cout << array[i]->getBusID() << "\t\t" << array[i]->getmanufacturer()
- << "\t\t" <<setw(5) <<array[i]->getCapacity() << "\t\t"<<array[i]-> getMileage() << "\t" << setw(5) <<array[i]->getStatus() << '\n';
- i++;
- }
- cout << "---end of list---" << endl;
- }
- /*
- * Bus.h
- *
- * Created on: Oct 7, 2019
- * Author: Mohammad
- */
- #include <string>
- #include <iostream>
- #ifndef BUS_H_
- #define BUS_H_
- using namespace std;
- class Bus{
- private:
- string busID;
- string manufacturer;
- int capacity;
- int mileage;
- char status;
- public:
- Bus();
- Bus(string,string,int,int,char);
- string getBusID();
- string getmanufacturer();
- int getCapacity();
- int getMileage();
- char getStatus();
- void setStatus(char);
- };
- #endif /* BUS_H_ */
- /*
- * Bus.cpp
- *
- * Created on: Oct 9, 2019
- * Author: Mohammad
- */
- #include "Bus.h"
- #include <iostream>
- #include <string>
- using namespace std;
- Bus::Bus(string bus,string manu,int cap,int miles,char stat){
- busID = bus;
- manufacturer = manu;
- capacity = cap;
- mileage = miles;
- status = stat;
- }
- string Bus::getBusID(){
- return busID;
- }
- string Bus::getmanufacturer(){
- return manufacturer;
- }
- int Bus::getCapacity(){
- return capacity;
- }
- int Bus::getMileage(){
- return mileage;
- }
- char Bus::getStatus(){
- return status;
- }
- void Bus::setStatus(char x){
- status = x;
- }
- #include "bus.h"
- #include <fstream>
- #include <iomanip>
- #ifndef FUNCTIONS_HPP_
- #define FUNCTIONS_HPP_
- void display(Bus * []);
- void setArray(Bus * [],fstream &);
- void listt(Bus*[],string);
- void change(Bus*[],string);
- #endif /* FUNCTIONS_HPP_ */
- #include "functions.h"
- void listBus(Bus* array[],string x){
- int i =0;
- int y = 0;
- while( array[i] != nullptr){
- if(array[i]->getBusID() == x.substr(2,5)){
- cout << "=======================================================================\n";
- cout << "BUS ID\t\t" << "BUS MANUFACTURER\t" << "BUS CAPACITY\t" << "MILEAGE\t" <<setw(5) <<"Status" << endl;
- cout << "=======================================================================\n";
- cout << array[i]->getBusID() << "\t\t" << array[i]->getmanufacturer()
- << "\t\t" <<setw(5) <<array[i]->getCapacity() << "\t\t"<<array[i]-> getMileage() << "\t" << setw(5) <<array[i]->getStatus() << '\n';
- cout << "---end of list---" << endl;
- y++;
- }
- i++;
- }
- if(y <= 0){
- cout << "Not Found" << endl;
- }
- }
- void change(Bus* array[],string x){
- int i = 0;
- int y = 0;
- while(array[i] != nullptr){
- if(array[i]->getBusID() == x.substr(2,5)){
- cout << "Change successful!" << endl;
- array[i]->setStatus(x.c_str()[8]);
- y++;
- }
- i++;
- }
- if(y <= 0){
- cout <<"not Found" << endl;
- }
- }
- void display(Bus * array[]){
- int i = 0;
- cout << "=======================================================================\n";
- cout << "BUS ID\t\t" << "BUS MANUFACTURER\t" << "BUS CAPACITY\t" << "MILEAGE\t" <<setw(5) <<"Status" << endl;
- cout << "=======================================================================\n";
- while(array[i] != nullptr){
- cout << array[i]->getBusID() << "\t\t" << array[i]->getmanufacturer()
- << "\t\t" <<setw(5) <<array[i]->getCapacity() << "\t\t"<<array[i]-> getMileage() << "\t" << setw(5) <<array[i]->getStatus() << '\n';
- i++;
- }
- cout << "---end of list---" << endl;
- }
- #include <string>
- #include <iostream>
- #ifndef BUS_H_
- #define BUS_H_
- using namespace std;
- class Bus{
- private:
- string busID;
- string manufacturer;
- int capacity;
- int mileage;
- char status;
- public:
- Bus();
- Bus(string,string,int,int,char);
- string getBusID();
- string getmanufacturer();
- int getCapacity();
- int getMileage();
- char getStatus();
- void setStatus(char);
- };
- #endif /* BUS_H_ */
- /*
- * Bus.cpp
- *
- * Created on: Oct 9, 2019
- * Author: Mohammad
- */
- #include "Bus.h"
- #include <iostream>
- #include <string>
- using namespace std;
- Bus::Bus(string bus,string manu,int cap,int miles,char stat){
- busID = bus;
- manufacturer = manu;
- capacity = cap;
- mileage = miles;
- status = stat;
- }
- string Bus::getBusID(){
- return busID;
- }
- string Bus::getmanufacturer(){
- return manufacturer;
- }
- int Bus::getCapacity(){
- return capacity;
- }
- int Bus::getMileage(){
- return mileage;
- }
- char Bus::getStatus(){
- return status;
- }
- void Bus::setStatus(char x){
- status = x;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement