Construct a program in C++ to calculate a net selling price of a car from variety of models. The requirement of the program are:

a. The program should be developed according to object oriented programming language which contain:
i. A class with a proper naming convention.
ii. A constructor with attributes - brand, model, year, price.

b. A static void method to calculate the discounted price with year and price as its parameters. In this method, test the input using single if control statement: - If the model produced in the year above 2020, then no discount will be given

  • If the model produced in the year of 2018 until 2020, then the discount is 10% from the original price of the car
  • If the model produced in the year of 2016 until 2017, then the discount is 20% from the original price of the car
  • If the model produced in the year of 2014 until 2015, then the discount is 30% from the original price of the car
  • If the model produced in the year of 2012 until 2013, then the discount is 40% from the original price of the car
  • If the model produced in the year less than 2012, then the discount is 50% from the original price of the car

c. Construct main() as a driver which input the brand, model, year and price from the keyboard.

d. Loop the user input twice using iteration control statement where the looping should initiate from 1 until 2 respectively.

e. Create an object of the class to invoke the year and price into the discount method.

Please help me. Thank you.

This looks like homework. As such you get to write and do the homework so let's hear where you are stuck.

commented: yea it is my Final Assessment. I tried and this is how far I can get. +0
#include <iostream>

using namespace std;

string model, brand;
int price,year,discountprice,afterdiscount;

class myclass{
    public
    void calculate() {
        cout<<"Welcome to Pandu Cepat Auto"<<endl;
        cout<<"For Model: "<<year<<endl;
        if (year=2018||year=2019||year=2020){
            discountprice=(price=10/100);
            afterdiscount=price - discountprice;
            cout<<"discount 10%:"<<discountprice<<endl;
        }else if (year=2016||year=2017){
            discountprice=(price=20/100);
            afterdiscount=price - discountprice;
            cout<<"discount 20%:"<<discountprice<<endl;
        }else if (year=2014||year=2015){
            discountprice=(price=30/100);
            afterdiscount=price - discountprice;
            cout<<"discount 30%:"<<discountprice<<endl;
        }else if (year=2012||year=2013){
            discountprice=(price=40/100);
            afterdiscount=price - discountprice;
            cout<<"discount 40%:"<<discountprice<<endl;
            else if (year<2012{
            discountprice=(price=50/100);
            afterdiscount=price - discountprice;
            cout<<"discount 50%:"<<discountprice<<endl;
    }
}

Am stuck

The first portion of the assignment says that the program should be object oriented with a constructor with attributres brand, model, year, and price.

Therefore, what we're talking about is a program which has different Car objects. Each Car object is a type of Car, with its own combination of brand, model, year, and price.

Therefore, the name of the class should be Car or something like that, and properties of a Car should be the variables brand, model, year, and price.

Then, you can create a new Car called MyCar, a new Car called YourCar, a new Car called NeighborCar, etc.

Then, there should be a method within this Car class to calculate the price. Then, I can do something like MyCar->calculatePrice(), or NeighborCar->calculatePrice() and see who has a more expensive car.

I'm frankly baffled by the requirement for a static void method to calculate what should be an instance variable, using existing instance variables. It makes absolutely no sense.

commented: I've seen bad programming habits taught in classrooms for decades now. +15
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.