contestada

Clunker Motors Inc. is recalling all vehicles in its Extravagant line from model years 1999-2002. A boolean variable named recalled has been declared. Given a variable modelYear and a String modelName write a statement that assigns true to recalled if the values of modelYear and modelName match the recall details and assigns false otherwise.

Respuesta :

C++ Code:

#include <iostream>

#include <string>

using namespace std;

int main()

{

   int modelYear;

   string modelName;

   bool Recalled;

cout<<"Please Enter the car model year"<<endl;

cin>>modelYear;

cout<<"Please Enter the name of the car"<<endl;

cin>>modelName;

if (modelYear>=1999 && modelYear<=2002)

  {

   if (modelName=="Clunker")

   {

       Recalled=true;

       cout<<Recalled<<" Recalled..."<<endl;

   }

       Recalled=false;

       cout<<Recalled<<" Not Recalled..."<<endl;

  }

   else

   {

       Recalled=false;

       cout<<Recalled<<" Not Recalled..."<<endl;

   }

   return 0;

}

Output:

Test 1:

Please Enter the car model year

2000

Please Enter the name of the car

Clunker

1 Recalled...

Test 2:

Please Enter the car model year

2000

Please Enter the name of the car

leste

0 Not Recalled...

Test 3:

Please Enter the car model year

2005

Please Enter the name of the car

clunker

0 Not Recalled...

Explanation:

The problem was to assign a bool variable Recalled true or false depending upon the conditions whether user enters a correct car model year and name of the car.

If else conditions are being used verify if user has entered correct credentials or not. When the conditions are met bool returns a value of 1 and when any one of the condition is not met then bool returns a value of 0

The code has been tested with several inputs and it returns correct output results.