Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please use C++ to write the codes. Thanks! Question 3 The objectives of the ques

ID: 3724566 • Letter: P

Question

Please use C++ to write the codes. Thanks!

Question 3 The objectives of the question This question is based on contents covered in Chapter 6 of text. are to: (a) implement the methods as per given class requirements (b) write the test driver to test the given methods (c) write file processing code Examine the given class specification, data files, additional information and answer the following questions: class Ticket private string id; string category: int scatno; double price double discount public: Ticket(string = " ", string = ", int-o, double-0, double-0); void setTicket(string, string, int, double, double) string getldo; string getCategory0: int getScatnoO: double getPrice0 double getDiscountO: class Salcs private Ticket tic[50]: int tcount public: void sortFile(string); Class Ticket Data member/method Ticket(stringstring Constructor. ",int-0, double 0 double -0) void setTicket(string, string, int, double, Assigns the values pass-in arguments to the data members. string getldo trin int getSeatnoO double getPrice0 doublc getDiscounto: Class Sales Remarks void sortFile(string), Reads the data from the three input fi stores them ALL in the Ticker array ric rcount keeps track of total number of elements in the Ticket array ric. Sorts the tie array based on the object member name given as argument. Writes the sorted data in tic array to the same file sales dat les sales dat and . The data member sales dat (input) 018 ilve 21 40 5 028 aive 101 40 5 2040 silver 121 405 8050 gold27 50 8070 gold 28 50 salesdat (out sorted by 'seat number (third column 8011 ve 20 50 8018silver 21 405 050gold 27 50 3 8070gold2 50 028 Blver 101 40 6nO40 ilver 121 40 5 Table 3.1 Input and Output Data Files

Explanation / Answer

Save the below code in your project folder (all files). Create sales.dat file with file content as per your question. kepp sales.dat in the same directory. Build your program and run. the sales.dat file will change after your program run.

/*****************/

/*
* Ticket.h
*
* Created on: 06-Mar-2018
*      Author: tan
*/
#include <string>
using namespace std;
#ifndef TICKET_H_
#define TICKET_H_

class Ticket {
private:
   string id;
   string category;
   int seatno;
   double price;
   double discount;
public:
   Ticket(string="",string="",int=0,double=0,double=0);
   void setTicket(string,string,int,double,double);
   string getId();
   string getCategory();
   int getSeatno();
   double getPrice();
   double getDiscount();
};

#endif /* TICKET_H_ */


/***************/

/*
* Ticket.cpp
*
* Created on: 06-Mar-2018
*      Author: tan
*/

#include "Ticket.h"

Ticket::Ticket(string Id,string cat,int sno,double prc,double dis) {
   // TODO Auto-generated constructor stub
   id=Id;
   category=cat;
   seatno=sno;
   price=prc;
   discount=dis;
}

void Ticket::setTicket(string Id,string cat,int sno,double prc,double dis){
   id=Id;
   category=cat;
   seatno=sno;
   price=prc;
   discount=dis;
}
string Ticket::getId(){
   return id;
}
string Ticket::getCategory(){
   return category;
}
int Ticket::getSeatno(){
   return seatno;
}
double Ticket::getPrice(){
   return price;
}
double Ticket::getDiscount(){
   return discount;
}


/*******************/

/*
* Sales.h
*
* Created on: 06-Mar-2018
*      Author: tan
*/
#include "Ticket.h"
#include <sstream>
#ifndef SALES_H_
#define SALES_H_

class Sales {
private:
   Ticket tic[50];
   int tcount;
public:
   Sales();
   void sortFile(string);
   void fillArray(string);
   string writeFile(int);
   int getCount();
};

#endif /* SALES_H_ */


/************************/

/*
* Sales.cpp
*
* Created on: 06-Mar-2018
*      Author: tan
*/

#include "Sales.h"
extern fstream file;
Sales::Sales() {
   // TODO Auto-generated constructor stub
   tcount=0;
}

void Sales::sortFile(string name){
   if(name=="id")
   {
           for(int i=0;i<tcount;i++){
           for(int j=i+1;j<tcount;j++){
               if(tic[i].getId()>tic[j].getId()){
                   Ticket t=tic[i];
                   tic[i]=tic[j];
                   tic[j]=t;
               }
           }
       }
   }
   else if(name=="category")
   {
           for(int i=0;i<tcount;i++){
           for(int j=i+1;j<tcount;j++){
               if(tic[i].getCategory()>tic[j].getCategory()){
                   Ticket t=tic[i];
                   tic[i]=tic[j];
                   tic[j]=t;
               }
           }
       }
   }
   else if(name=="seat no")
   {
           for(int i=0;i<tcount;i++){
           for(int j=i+1;j<tcount;j++){
               if(tic[i].getSeatno()>tic[j].getSeatno()){
                   Ticket t=tic[i];
                   tic[i]=tic[j];
                   tic[j]=t;
               }
           }
       }
   }

}
void Sales::fillArray(string line){
   stringstream ss(line);
   string id;
   int sno;
   double pric;
   double dis;
   string category;
   ss>>id>>category>>sno>>pric>>dis;

   tic[tcount].setTicket(id,category,sno,pric,dis);
   tcount++;
}
string Sales::writeFile(int i){
   stringstream ss;
   string str;
   string line;
   ss<<tic[i].getId()<<tic[i].getCategory()<<tic[i].getSeatno()<<tic[i].getPrice()<<tic[i].getDiscount();
   ss>>str;
   str=str+" ";
   return str;
}
int Sales::getCount(){
   return tcount;
}


/*********************/

//============================================================================
// Name        : MovieTicket.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include "Sales.h"
#include <iostream>
#include <fstream>
using namespace std;
fstream file;
int main() {
   Sales sale;
   fstream file;
   file.open("sales.dat");
   string line;

   while(!file.eof()){
   getline(file,line);
   sale.fillArray(line);
   }
   file.seekg(0,ios::beg);
   sale.sortFile("seat no");
   for(int i=0;i<sale.getCount();i++){
       file<<sale.writeFile(i);
   }

   file.close();
   return 0;
}


/*********************/sales.dat(fill this file)

a109 silver 15 45 3
a018 silver 12 40 5