SophiaPretty

(5)

$14/per page/Negotiable

About SophiaPretty

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing Hide all
Teaching Since: Jul 2017
Last Sign in: 304 Weeks Ago, 2 Days Ago
Questions Answered: 15833
Tutorials Posted: 15827

Education

  • MBA,PHD, Juris Doctor
    Strayer,Devery,Harvard University
    Mar-1995 - Mar-2002

Experience

  • Manager Planning
    WalMart
    Mar-2001 - Feb-2009

Category > Engineering Posted 28 Nov 2017 My Price 10.00

difficult time with just printing out ALL data for all cars.

Hello,

This is for my CS202 class where we are coding in c++. I am having a difficult time with just printing out ALL data for all cars. I know my readFile function needs adjustment, I just do not know how.

 

Description:

For this project, you are to create a program that will assist users who want to rent a car. You are given a datafile with 10 different cars, and you must read in all of the car data from the file and store it in an array of structs. You must also create a menu with the functionality defined below. Although an example file is provided, for grading purposes your project will be tested against a different test file that will not be provided to you beforehand. Our test file will be in the same format as the example file.

 

The RentalCar struct will contain the following data members:

- make, a C-style string

- model, a C-style string

- year, an int

- price, a float (price per day)

- available, a bool (1 = true; 0 = false; try to display true/false using the "boolalpha" flag, optional)

 

The menu must have the following functionality:

- Read ALL data from file.

- Print out ALL data for all of the cars.

- Estimate car rental cost - prompt the user for a car number (first car in file should be

represented to the user as #1), and the number of days to rent the car.

- Find the most expensive car.

- Print out ONLY the available cars.

- Exit program.

 

The following minimum functionality and structure is required:

- Ask the user for the input file name.

- The list of cars must be stored in an array of structs.

- Use character arrays (i.e., C-style) to hold your strings. No string data type!

- Write multiple functions (Hint: each menu option should be a function).

- You can use pass by reference in your function.

- Write your own string copy, string compare (or other) functions as needed.

- The other functionality and structure of the program should remain the same as Project #1, including writing to screen and file and restrictions on string libraries, global variables and constants, etc.#include <iostream>
#include <fstream>

//using namespace std;

const int MAX_STRING_LENGTH = 50;
const int MAX_NUM_CARS = 10;

struct rentalCar
{
    char make[MAX_STRING_LENGTH];
    char model[MAX_STRING_LENGTH];
    int year;
    float price;
    bool availability;
};

// Function Prototypes
void readFile(char fileName[]);
void displayCarData(rentalCar cars);
void carEstimate(rentalCar car, int days);
void mostExpensive(rentalCar cars[]);
void availableCars(rentalCar cars[]);
int showMenu();

int main ()
{
    char nameOfFile[MAX_STRING_LENGTH];
    int menuChoice;
    bool programOn;
    rentalCar vehicles[MAX_NUM_CARS];

    
    std:: cout << "Enter file name: ";
    std:: cin >> nameOfFile;
    
    readFile(nameOfFile);
    
    do
    {
    
        menuChoice = showMenu();
        
        switch(menuChoice)
        {
            case 1:
                for(int i=0; i < MAX_NUM_CARS; i++)
                {
                std:: cout << i+1 << ") " ;
                displayCarData(vehicles[i]);
                }
                break;
            
            case 2:
                {
                int carNum = 0;
                int days = 0;

                std:: cout << "Enter car number" << std:: endl;
                std:: cin >> carNum;
                std:: cout << std:: endl;

                std:: cout << "Enter number of days" << std:: endl;
                std:: cin >> days;
                std:: cout << std:: endl;

                carNum--;

                carEstimate(vehicles[carNum], days);
                break;
                }
                
            case 3:
                mostExpensive(vehicles);
                break;
                
            case 4:
                break;            
                
            default:
                return 0;
                break;    
        }
    }while(programOn);
    
    
    
}

void readFile(char fileName[])
{
    std:: ifstream fileIn;
    rentalCar read;

    
    fileIn.open(fileName);
    
    //for(int i=0; i< MAX_NUM_CARS; i++)
    //{
        fileIn >> read.year;
        fileIn >> read.make;
        fileIn >> read.model;
        fileIn >> read.price;
        fileIn >> read.availability;
        
        fileIn>> read;
    //}
    
        
}

void displayCarData(rentalCar cars)
{    
    
        std:: cout << cars.year << " "
               << cars.make << " "
               << cars.model << " "
               << cars.price << " per day "
               << "Available: ";
               
        if(cars.availability == true)
        {
            std:: cout << "true" << std:: endl;
        }
        else
        {
            std:: cout << "false" << std:: endl;
        }
    
}

void carEstimate(rentalCar car, int days)
{
    float cost = 0.0;

    cost = car.price * days;

    std:: cout << "Estimated cost of renting is: " << cost << std:: endl;
}

void mostExpensive(rentalCar cars[])
{
    float max = 0.0;
    int maxCar = 0;

    for(int i = 0; i < 10; i++) {
        if(cars[i].price > max) {
            max = cars[i].price;
            maxCar = i;
        }
    }

    std:: cout << "The most expensive car is: "
         << cars[maxCar].year <<  " "
         << cars[maxCar].make << " "
         << cars[maxCar].model << std:: endl;
}
void availableCars(rentalCar[])
{
    
}

int showMenu()
{
    int userInput;
    
    std:: cout << std:: endl << " Rental Car Service" << std:: endl;
    std:: cout << " ==================" << std:: endl << std:: endl;
    
    std:: cout << "1. Print data for all cars" << std:: endl;
    std:: cout << "2. Estimate car rental cost" << std:: endl;
    std:: cout << "3. Find the most expensive car" << std:: endl;
    std:: cout << "4. Print data for available cars" << std:: endl;
    std:: cout << "5. Exit program" << std:: endl << std:: endl;
    std:: cout << "Enter selection: " ;
    
    std:: cout << "Enter selection choice: " ;
    std:: cin >> userInput;
    
    std:: cout << std:: endl;
    
    return userInput;
}

Attachments:

Answers

(5)
Status NEW Posted 28 Nov 2017 01:11 PM My Price 10.00

-----------  ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly

Not Rated(0)