Create a class Car, which contains Three data members i.e. carName (of string type), ignition (of bool type), and currentSpeed (of integer type)
 A no-argument constructor to initialize all data members with default values
 A parameterized constructor to initialize all data members with user-defined values
 Three setter functions to set values for all data members individually
 Three getter function to get value of all data members individually
 A member function setSpeed( ) // takes integer argument for setting speed
Derive a class named Convertible that contains
 A data member top (of Boolean type)
 A no-argument constructor to assign default value as “false” to top
 A four argument constructor to assign values to all data-members i.e. carName, ignition, currentSpeed and top.
 A setter to set the top data member up
 A function named show() that displays all data member values of invoking object
Write a main() function that instantiates objects of Convertible class and test the functionality of all its member functions.

Answers

Answer 1

Answer:

Here.

Explanation:

#include <iostream>

#include <string>

using namespace std;

//Create a class Car, which contains • Three data members i.e. carName (of string type), ignition (of bool type), and //currentSpeed (of integer type)

class Car

{

public:

string carName;

bool ignition;

int currentSpeed;

//A no-argument constructor to initialize all data members with default values

//default value of string is "",bool is false,int is 0

Car()

{

carName="";

ignition=false;

currentSpeed=0;

}

//A parameterized constructor to initialize all data members with user-defined values

Car(string name,bool i,int speed)

{

carName=name;

ignition=i;

currentSpeed=speed;

}

//Three setter functions to set values for all data members individually

// Three getter function to get value of all data members individually

void setCarName(string s)

{

carName=s;

}

void setIgnition(bool ig)

{

ignition=ig;

}

void setCurrentSpeed(int speed)

{

currentSpeed=speed;

}

string getCarName()

{

return carName;

}

bool getIgnition()

{

return ignition;

}

int getCurrentSpeed()

{

return currentSpeed;

}

//A member function setSpeed( ) // takes integer argument for setting speed

void setSpeed(int sp1)

{

currentSpeed=sp1;

}

};

//Derive a class named Convertible

class Convertible:public Car

{

//A data member top (of Boolean type)

public:

bool top;

public:

//A no-argument constructor to assign default value as “false” to top

Convertible()

{

top=false;

}

//A four argument constructor to assign values to all data-members i.e. carName, ignition,

//currentSpeed and top.

Convertible(string n,bool i,int s,bool t):Car(n,i,s)

{

carName=n;

ignition=i;

currentSpeed=s;

top=t;

}

// A setter to set the top data member up

void setTop(bool t)

{

top=t;

}

//A function named show() that displays all data member values of invoking object

void show()

{

cout<<"Car name is:"<<carName<<endl;

cout<<"Ignition is: "<<ignition<<endl;

cout<<"Current Speed is :"<<currentSpeed<<endl;

cout<<"Top is:"<<top<<endl;

}

};

//main function

int main()

{

//creating object for Convertible class

Convertible c1("Audi",true,100,true);

c1.show();

c1.setCarName("Benz");

c1.setIgnition(true);

c1.setCurrentSpeed(80);

c1.setTop(true);

c1.show();

cout<<"Car Name is: "<<c1.getCarName()<<endl;

cout<<"Ignition is:"<<c1.getIgnition()<<endl;

cout<<"Current Speed is:"<<c1.getCurrentSpeed()<<endl;

return 0;

}

Answer 2

The following are the program to the given question:

Program Explanation:

Defining the header file.Defining a class "Car", inside the three variables "carName, ignition, and currentSpeed" is declared that are "string, bool, and integer" types.Inside the class, "default and parameterized constructor" and get and set method has defined that set and returns the parameter values.Outside the class, another class "Convertible" (child) is declared that inherit the base class "Car".Inside the child class, "default and parameterized constructor" is defined, which inherits the base class constructor.In the child class parameterized constructor it takes four parameters, in which 3 are inherited from the base class and one is bool type that is "t".In this class, a method "setTop" is defined that sets the "t" variable value and defines a show method that prints the variable values.Outside the class, the Main method is defined that creating the child class object and calling the parameterized constructor and other methods to print its values.

Program:

#include <iostream>//header file

#include <string>

using namespace std;

class Car//defining a class Car

{

//defining a data members

public:

string carName;//defining string variable

bool ignition;//defining bool variable

int currentSpeed;//defining integer variable

Car()//defining default constructor

{

carName="";//initiliaze a space value in string variable

ignition=false;//initiliaze a bool value in bool variable

currentSpeed=0;//initiliaze an integer value into int variable

}

Car(string name,bool i,int speed)//defining parameterized constructor that holds value into the variable

{

carName=name;//holding value in carName variable

ignition=i;//holding value in ignition variable

currentSpeed=speed;//holding value in currentSpeed variable

}

void setCarName(string s)//defining a set method that takes parameter to set value into the variable

{

carName=s;//set value

}

void setIgnition(bool ig)//defining a set method that takes a parameter to set value into the variable

{

ignition=ig;//set value

}

void setCurrentSpeed(int speed)//defining a set method that takes a parameter to set value into the variable

{

currentSpeed=speed;//set value

}

string getCarName()//defining a get method that return input value

{

return carName;//return value

}

bool getIgnition()//defining a get method that return input value

{

return ignition;//return value

}

int getCurrentSpeed()//defining a get method that return input value

{

return currentSpeed;//return value

}

void setSpeed(int sp1)//defining a method setSpeed that holds parameter value

{

currentSpeed=sp1;//hold value in currentSpeed

}

};

class Convertible:public Car//defining a class currentSpeed that inherits Car class

{

public:

bool top;//defining bool variable

public:

Convertible()//defining default constructor

{

top=false;//holing bool value

}

Convertible(string n,bool i,int s,bool t):Car(n,i,s)//defining parameterized constructor Convertible that inherits base class parameterized constructor

{

carName=n;//holding value in string variable

ignition=i;//holding value in bool variable

currentSpeed=s;//holding value in integer variable

top=t;//holding value in bool variable

}

void setTop(bool t)//defining a method setTop that takes parameter to set bool value

{

top=t;//holding bool value

}

void show()//defining show method that prints variable value

{

cout<<"Car name is:"<<carName<<"\n";//prints value

cout<<"Ignition is: "<<ignition<<"\n";//prints value

cout<<"Current Speed is :"<<currentSpeed<<"\n";//prints value

cout<<"Top is:"<<top<<"\n";//prints value

}

};

int main()//defining a main method

{

Convertible cs("BMW",true,180,true);//creating the Convertible calss object that calls the parameterized constructor by accepting value into the parameter

cs.show();//calling method show

cs.setCarName("Benz");//calling the setCarName method

cs.setIgnition(true);//calling the setIgnition method

cs.setCurrentSpeed(160);//calling setCurrentSpeed method

cs.setTop(true);//calling setTop method

cs.show();//calling show method

cout<<"Car Name is: "<<cs.getCarName()<<"\n";//calling the getCarName method and print its value

cout<<"Ignition is:"<<cs.getIgnition()<<"\n";//calling the getIgnition method and print its value

cout<<"Current Speed is:"<<cs.getCurrentSpeed();//calling the getCurrentSpeed method and print its value

return 0;

}

Output:

Please find the attached file.

Learn more:

brainly.com/question/23313563

Create A Class Car, Which Contains Three Data Members I.e. CarName (of String Type), Ignition (of Bool

Related Questions

Which of these elements help të orient a user?
to
A
a dialog
B.
page name
c. an icon
b. a banner




Fast please

Answers

answer:

page name

Explanation:

Answer:

b. page name

Explanation:

plato

Create a new Java project/class called ChangeUp. Create an empty int array of size 6. Create a method called populateArray that will pass an array, use random class to choose a random index and prompt the user to enter a value, store the value in the array. Note: Generate 6 random index numbers in an attempt to fill the array. Create a method called printArray that prints the contents of the array using the for each enhanced loop. Submit code. Note: It is possible that your array won't be filled and some values will still have 0 stored. That is acceptable.

Answers

Answer:

//import the Random and Scanner classes

import java.util.Random;

import java.util.Scanner;

//Begin class definition

public class ChangeUp {

   

   //Begin the main method

  public static void main(String args[]) {

       //Initialize the empty array of 6 elements

      int [] numbers = new int [6];

       

       //Call to the populateArray method

       populateArray(numbers);

       

       

   } //End of main method

   

   

   //Method to populate the array and print out the populated array

   //Parameter arr is the array to be populated

   public static void populateArray(int [] arr){

       

       //Create object of the Random class to generate the random index

       Random rand = new Random();

       

       //Create object of the Scanner class to read user's inputs

       Scanner input = new Scanner(System.in);

       

       //Initialize a counter variable to control the while loop

       int i = 0;

       

       //Begin the while loop. This loop runs as many times as the number of elements in the array - 6 in this case.

       while(i < arr.length){

           

           //generate random number using the Random object (rand) created above, and store in an int variable (randomNumber)

           int randomNumber = rand.nextInt(6);

       

           //(Optional) Print out a line for formatting purposes

           System.out.println();

           

           //prompt user to enter a value

           System.out.println("Enter a value " + (i + 1));

           

           //Receive the user input using the Scanner object(input) created earlier.

           //Store input in an int variable (inputNumber)

           int inputNumber = input.nextInt();

           

           

           //Store the value entered by the user in the array at the index specified by the random number

           arr[randomNumber] = inputNumber;

           

           

           //increment the counter by 1

          i++;

           

       }

       

       

       //(Optional) Print out a line for formatting purposes

       System.out.println();

       

       //(Optional) Print out a description text

      System.out.println("The populated array is : ");

       

       //Print out the array content using enhanced for loop

       //separating each element by a space

       for(int x: arr){

           System.out.print(x + " ");

       }

   

       

  } //End of populateArray method

   

   

   

} //End of class definition

Explanation:

The code above is written in Java. It contains comments explaining the lines of the code.

This source code together with a sample output has been attached to this response.

Answer:

import java.util.Random;

import java.util.Scanner;

public class ArrayExample {

   public static void main(String[] args) {

       int[] array = new int[6];

       populateArray(array);

       printArray(array);

   }

 

   public static void populateArray(int[] array) {

       Random random = new Random();

       Scanner scanner = new Scanner(System.in);

       boolean[] filledIndexes = new boolean[6];

     

       for (int i = 0; i < 6; i++) {

           int index = random.nextInt(6);

         

           while (filledIndexes[index]) {

               index = random.nextInt(6);

           }

         

           filledIndexes[index] = true;

         

           System.out.print("Enter a value for index " + index + ": ");

           int value = scanner.nextInt();

           array[index] = value;

       }

   }

 

   public static void printArray(int[] array) {

       System.out.println("Array contents:");

       for (int value : array) {

           System.out.print(value + " ");

       }

   }

}

Explanation:

In the code provided, we are creating an array of size 6 to store integer values. The objective is to populate this array by taking input from the user for specific indexes chosen randomly.

To achieve this, we have defined two methods: populateArray and printArray.

The populateArray method takes an array as a parameter and fills it with values provided by the user. Here's how it works:

We create an instance of the Random class to generate random numbers and a Scanner object to read user input.We also create a boolean array called filledIndexes of the same size as the main array. This array will keep track of the indexes that have already been filled.Next, we use a loop to iterate six times (since we want to fill six elements in the array).Inside the loop, we generate a random index using random.nextInt(6). However, we want to make sure that we don't fill the same index twice. So, we check if the index is already filled by checking the corresponding value in the filledIndexes array.If the index is already filled (i.e., filledIndexes[index] is true), we generate a new random index until we find an unfilled one.Once we have a valid, unfilled index, we mark it as filled by setting filledIndexes[index] to true.We then prompt the user to enter a value for the chosen index and read the input using scanner.nextInt(). We store this value in the main array at the corresponding index.This process is repeated six times, ensuring that each index is filled with a unique value.

The printArray method is responsible for printing the contents of the array. It uses a for-each enhanced loop to iterate over each element in the array and prints its value.

**By separating the population and printing logic into separate methods, the code becomes more modular and easier to understand.**

Other Questions
While he was washing the car, Nancy went for a walk. The underlined part of the sentence is a/an... Select one: O subordinate clause. O noun phrase. O O relative clause. O independent clause. The wing of a bird and the leg of a horse are very different looking structures. Although they look different, bird wings and horse legs are very similar in the arrangement of the bones that make up the limb. Which term is used by scientists to describe structures that look different on the outside but are actually similar in construction and develop from the same embryonic tissues? es -0) A) common descent B) analogous structures vestigial structures D) homologous structures Answer: What is one religious connection Christians have to Jerusalem? Dont know how to do this and someone please do it for me! In which stage of mitosis do chromosomes first appear?AprophaseBmetaphaseanaphaseDtelophase Why do you think Europeans' views of Muslims changed when Europeans traveled to Muslim lands? can someone please help me please I will mark brainlist and give you 5 stars pleasee Homestead Jeans Co. has an annual plant capacity of 65,000 units, and current production is 45,000 units. Monthly fixed costs are $54,000, and variable costs are $29 per unit. The present selling price is $42 per unit. On November 12 of the current year, the company received an offer from Dawkins Company for 18,000 units of the product at $32 each. Dawkins Company will market the units in a foreign country under its own brand name. The additional business is not expected to affect the domestic selling price or quantity of sales of Homestead Jeans Co.Required:a. Prepare a differential analysis dated November 12 on whether to reject (Alternative 1) or accept (Alternative 2) the Dawkins order.b. Briefly explain the reason why accepting this additional business will increase operating income.c. What is the minimum price per unit that would produce a positive contribution margin? How did Thomas Paine's pamphlet Common Sense convince reluctant Americans to abandon the goal of reconciliation with Britain and accept that separation from Britain independence was the only option for preserving their liberty? In this part of the laboratory exercise, you will learn how to read a weather station model. Using your Earth Science Reference Tables, fill in the data tables below each station model. F/R/E/E P/O/I/N/T/S Did anybody laugh when the ice skater fell down? 1. Nomenclature is governed by certain universal rules. Which one of the following is contrary to the rules of nomenclature? WILL MARK BRIANLYEST!! Cross an individual who is heterozygous for baldness with one who is hom0zygous recessive. If the children were all boys, what would the phenotypic ratio for the above cross be? What would the phenotypic ratio be if they were all girls? Read the sentence:She was saddened by the loss of her soccer game, but she knew she would rebound soon.The prefix re- means again. What does the word rebound mean as it is used in this sentence? To be happy again To jump again To score again To spring back After World War II, Stalin said that the Soviet Union needed a buffer zone to protect it from attack. This idea resulted in the USSR expanding its control into ?Northern Africa.Western Europe.the Middle East.Eastern Europe. help for brainliest plz How to write an equation in point -slope form for each line 24.8x45.67 plz help will mark Brainliest Marcella is aware that if they deliver their speech standing too far to oneside of the stage, or standing too closely to the back wall, or standing tooclosely to the audience, then their audience will have trouble focusing onthem. Marcella therefore makes the very simple, strategic decision to standcenter stage, evenly spaced between the audience and the back wall.Marcella is most clearly concerned with the following quality of physicaldeliver:O PositioningO Facial expressionsO GesturesO Eye contact