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

Write a complete c++ program which involves car rental customers and the number

ID: 666848 • Letter: W

Question

Write a complete c++ program which involves car rental customers and the number of cars each customer has rented.

The program will have two input files and one output file. Input file #1 will have the customers last name first name in format:

lastname1 firstname1

lastname2 firstname2

and so on to a maximum of 18 customers, with the maximum name length of 12 characters per for the first name and 12 for the last name.

The second input file will have customers who have rented cars, from the first input file. Note that the customers may not have rented any cars and will not have their names present(the maximum number of rentals per customer is 10). The format for the second file will be:

lastname num num num

lastname2 num num, where the num represents the rental price of that particular rental

Overall the program will write to an output file opened in the beginning and struct must be used for the data. The program order will be as follows:

create an ouput file to write onto, then prompt for the name of the 1st file to then read and count the names.

Then alphebatize the names to the output file and prompt for the 2nd input file.

Read the 2nd input file and locate the record of the customer from the 1st input file and read the number of cars rented and store it into the rental field.

Then write the results to the ouput listing the customers, the number of rentals and the prices of such rentals, and total the amount due per customer. Functions are required for each process.

Explanation / Answer

#include<iostream>
#include<fstream>
#include<string.h>

using namespace std;

//method to return the firstname based on the lastname
char* getFirstName(char lname[12],char lastname[18][12],char firstname[18][12],int count){
    int i;
    for(i=0;i<count;i++){
        if(strcmp(lname,lastname[i])==0){
            return firstname[i];
        }
    }
    return "";
}

int main(){
    ofstream output;
    ifstream input1,input2;
    char fname1[10],fname2[10];
    char lastname[18][12],firstname[18][12],lname[12];
    int numOfCars,price;
    output.open("d:out.txt");
    cout<<"Enter the name of the first file: "; //accept the name of the first input file
    cin>>fname1;
    input1.open(fname1);
    int count=0;
    while(!input1.eof()){   //read lastnames and firstnames from 1st input file and store in array
        input1>>lastname[count];
        input1>>firstname[count];
        count++;
    }
    cout<<"Enter the name of second file: ";    //accept the name of second input file
    cin>>fname2;
    input2.open(fname2);
    while(!input2.eof()){   //read data from 2nd input file
        input2>>lname;
        input2>>numOfCars;
        input2>>price;
        char *fname=getFirstName(lname,lastname,firstname,count);   //get the corresponding firstname
        output<<lname<<" "<<fname<<" "<<numOfCars<<" "<<price<<" "<<numOfCars*price<<endl; //write data to the output file
    }
    cout<<"Output file created";
    //close all the files
    input1.close();
    input2.close();
    output.close();
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote