Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need carads.h, w1_p1.cpp, w1_p2.cpp Here's the link for accessing the files: https://github.com/Seneca-345305/OOP-Workshops/tree/main/WS01/part%201 https://github.com/Seneca-345305/OOP-Workshops/tree/main/WS01/part%202 Car Ads This application records Car Ads made by different sellers

I need carads.h, w1_p1.cpp, w1_p2.cpp

Here's the link for accessing the files:

https://github.com/Seneca-345305/OOP-Workshops/tree/main/WS01/part%201

https://github.com/Seneca-345305/OOP-Workshops/tree/main/WS01/part%202

Car Ads

This application records Car Ads made by different sellers and calculates the price with according to the current tax rate and the special promotions on certain cars.

The application loads the ads information from multiple Ad files. Each file read represents an advertisement from one seller.

Part 1 (0%)

This workshop consists of two modules:

  • w1 (partially supplied)
  • carads

w1 Module (partially supplied)

Study the code supplied and make sure you understand it.

Finish the implementation of the main function, by completing the parts marked with TODO:

  • write the prototype of the main function to receive a set of standard command line arguments

Do not modify this module in any other place!

carads Module

The carads module have the following main parts:

Global Variables

The carads.h header file defines the current tax rate and the special promotion discount, as two global variables named g_taxrate and g_discount that stores double values. The value of the tax rate and special promotion discount may change from day to day. These two variables will be accessed and can be changed from the main function. So these variables are defined in this module and can be accessed from an external module (extern is used here).

Global Function

In namespace sdds, implement a function called listArgs that receives the same parameters as the main function (same types, same order).

In the implementation file, implement this function to echo the set of arguments to standard output in the following format:

Command Line: -------------------------- 1:  2:  3:  4: ... 

Class Cars

This module also defines a class named Cars in the namespace sdds that stores some information about a car ad:

a C-style null-terminated string of up to 10 characters including the null byte terminator representing the brand of the car.

a C-style null-terminated string of up to 15 characters including the null byte terminator representing the model of the car.

the manufacture year of the car.

the price of the car represented by a double value.

the status of the cars as used or new using a single character (holds N or U)

a boolean flag indicating whether or not the car is on promotion discount

Hint: use safe state for all data members {}

Public Members

default constructor

read(std::istream& is): a modifier.

  • If the istream is in a good state, this function will attempt to read from the istream and store the information read into current object. The data read in will be in the following format:
  • If the istream object is not in a good state then this function will do nothing.

display(bool reset): a query that displays to the screen the content of an Cars instance in the following format:

COUNTER. Brand | Model | Year |Price w/Tax |Special Price 

If no car brand has been stored in the current object, this query should print:

COUNTER. No Car 

where

  • COUNTER is a left aligned field of size 2, that holds the number of times that this function has been called (use a local-to-function variable that remains in memory for the lifetime of the program) Do not use global/member variables to store the counter!
  • Brand is a left aligned field of size 10 that represents the brand of the car.
  • Model is a left aligned field of size 15 that represents the model of the car.
  • Year is printed as is (assuming it is 4 field number).
  • Price w/Tax is a left aligned field of size 12 with 2 decimal point precision that represents the price of the car with tax calculated based on the current tax rate.
  • Special Price is a right aligned field of size 12 that represents the taxed price of the car current promotion applied on top if the order was a discounted price. If the order isn't a discounted car, then nothing is printed here.

char getStatus(): a query that returns if the car is new or used.

Add any other private members that your design requires (without changing the specs above)!

Sample Output

The input files ad1.txt and ad2.txt are already provided; the main module contains a description of the structure for these files.

When the program is started with the command:

ws ad1.txt ad2.txt ad3.txt ad4.txt 

the output should look like the one from the sample_output.txt file.

Test Your Code

To test and demonstrate execution of your program use the same data as shown in the output sample.

Upload your source code to your matrix account. Compile and run your code using the latest version of the g++ compiler (available at /usr/local/gcc/10.2.0/bin/g++) and make sure that everything works properly.

Then, run the following command from your account (replace profname.proflastname with your professor's Seneca userid):

~profname.proflastname/submit 345_w1_p1 

and follow the instructions.

This part represents a milestone in completing the workshop and is not marked!

Part 2 (100%)

For this part of the workshop, upgrade your Cars class to accept a car brand in the form of a C-style null-terminated string of any length. Make sure your program doesn't have memory leaks.

In order to facilitate the changes needed for this part, consider the use of these std::string related functions:

  • std::getline
  • std::string::c_str
  • std::string::length

Implement the rule-of-3. Explain in the reflection why these functions are necessary and in what situation a class must implement them.

Enhance the carads module, by adding the following:

Member Functions

  • conversion to bool operator that returns true if the car is new, false otherwise.

Global Functions

  • std::istream& operator>>(std::istream& is, Cars& car): has the same functionality as Cars::read().
  • void operator>>(const Cars& car1, Cars& car2): copies in the second parameter the content of the first parameter.

Sample Output

When the program is started with the command:

ws ad1.txt ad2.txt ad3.txt ad4.txt 

the output should look like the one from the sample_output.txt file.

Note: files ad2.txt and ad4.txt are missing on purpose.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

=+1. What characterizes an AI application?

Answered: 1 week ago