Question
Question1
Lab4-2 VIEW TOOLS Enable Editing DTECTED VIEW Be careful-files from the Intermet can contain viruses. Unless you need to edit
)-W 1 1 2 2 3 3 4 0 99 5 Step 3: Improve the program so that only 1, 2, and 3 are accepted as valid choices. Make line 24 che

Question2
Labd-2 (Pro TOOLS VIEW FILE Enable Editing PROTECTED VIEW Be careful-files from the Internet can contain viruses. Unless you
ew)-We 36 return 0; 37) Step 2: Compile the program and then run it 7 times. For each run use the input test data shown in th
0 0
Add a comment Improve this question Transcribed image text
Answer #1

4.4

step 1: The program is as follows:

*********************************************************************************************************************************************

//Lab4 color.cpp
//This program lets the user select a primary color from a menu.
//put your name here
#include<iostream>
#include<string>
using namespace std;

int main()
{
   int choice; //Menu choice should be 1,2 or 3
  
   //Display the menu of choices
   cout << "Choose a primary color by entering its number.\n\n";
   cout << "1 Red\n" << "2 Blue\n" << "3 Yellow\n";
  
   //Get the user's choice
   cin >> choice;
  
   //Tell the user what he or she picked
   if(choice ==1)
   cout << "\nYou picked red.\n";
   else if(choice ==2)
   cout << "\nYou picked blue.\n";
   else
   cout << "\nYou picked yellow.\n";
  
   return 0;
}

**********************************************************************************************************************************

Step 2 : After compilation the output as recorded in the program is :

Run

Menu choice

Current Output

New output

1

1

You picked red.

2

2

You picked blue.

3

3

You picked yellow.

4

0

You picked yellow.

5

99

You picked yellow.

Screen shot of one of the output of the program is

Choose a primary color by entering its number. 1 Red 2 Blue 3 Yellow You picked red.

Step 3: Manipulating the program and adding choice 3 and trailing else the new program is as follows:

***********************************************************************************************************************************

//Lab4 color.cpp
//This program lets the user select a primary color from a menu.
//put your name here
#include<iostream>
#include<string>
using namespace std;

int main()
{
   int choice; //Menu choice should be 1,2 or 3
  
   //Display the menu of choices
   cout << "Choose a primary color by entering its number.\n\n";
   cout << "1 Red\n" << "2 Blue\n" << "3 Yellow\n";
  
   //Get the user's choice
   cin >> choice;
  
   //Tell the user what he or she picked
   if(choice ==1)
   cout << "\nYou picked red.\n";
   else if(choice ==2)
   cout << "\nYou picked blue.\n";
   else if(choice == 3)
   cout << "\nYou picked yellow.\n";
   else
   cout << "You have chosen a wrong choice!!";
  
   return 0;
}

*********************************************************************************************************************

After updation of the program the output is as follows :

Run

Menu choice

Current Output

New output

1

1

You picked red.

You picked red.

2

2

You picked blue.

You picked blue.

3

3

You picked yellow.

You picked yellow.

4

0

You picked yellow.

You have chosen a wrong choice!!

5

99

You picked yellow.

You have chosen a wrong choice!!

-------------------------------------------------------------------------------------------------------------------------------------------------------------------

4.5

The program of using nasted if/else is as follows:

****************************************************************************************************

//Lab 4 petTag.cpp
//This program determines the fee for a cat or dog pet tag.
//It uses nested if/else statement.
//PUT YOUR NAME HERE
#include<iostream>
#include<string>
using namespace std;
int main()
{
   string pet; //"cat" or "dog"
   char spayed; //'y' or 'n'
  
   //Get pet type and spaying information
   cout << "Enter the pet type (cat or dog): ";
   cin >> pet;
   cout << "Has the pet spayed or neutered (y/n)? ";
   cin >> spayed;
  
   //Determine the pet tag fee
   if(pet == "cat")
   {
       if(spayed == 'y')
       cout << "Fee is $4.00 \n";
       else
       cout << "Fee is $8.00 \n";
   }
   else if(pet == "dog")
   {
       if(spayed == 'y')
       cout << "Fee is $6.00 \n";
       else
       cout << "Fee is $12.00 \n";
   }
   else
       cout << "Only cats and dogs need pet tags. \n";
   return 0;
  
}

******************************************************************************************************************

The output as recorded after compilation and running of the program 7 times is as follows :

Run

Input data

Fee Information

Correct?

1

cat y

4

yes

2

cat n

8

yes

3

cat y

4

yes

4

dog y

6

yes

5

dog n

12

yes

6

dog y

6

yes

7

hamster n

error information

no

Here the error information is : "Only cats and dogs need pet tags."

You can run the program as well and record the output. The screen shot of one of the run of the program is given below

D. E:\Personal Chegg\petTag.exe Enter the pet type <cat or dog>: cat Has the pet spayed or neutered (u/n? UI Fee is $4.00 = =

Add a comment
Know the answer?
Add Answer to:
Question1 Question2 Lab4-2 VIEW TOOLS Enable Editing DTECTED VIEW Be careful-files from the Intermet can contain...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Х Enable Editing X i PROTECTED VIEW Be careful—files from the Internet can contain viruses. Unless...

    Х Enable Editing X i PROTECTED VIEW Be careful—files from the Internet can contain viruses. Unless you need to edit, it's safer to stay in Protected View. LAAM Yuuuus = (x2-x-2 1. (10 marks) Let f(x) (x2-4) if x # +2 с if x = 2 Find c that would make f continuous at 1. For such c, prove that f is continuous at 1 using an ε - 8 proof. 2. (10 marks) Prove that f(x) 6 ln(x –...

  • Х Enable Editing X i PROTECTED VIEW Be careful—files from the Internet can contain viruses. Unless...

    Х Enable Editing X i PROTECTED VIEW Be careful—files from the Internet can contain viruses. Unless you need to edit, it's safer to stay in Protected View. LAAM Yuuuus = (x2-x-2 1. (10 marks) Let f(x) (x2-4) if x # +2 с if x = 2 Find c that would make f continuous at 1. For such c, prove that f is continuous at 1 using an ε - 8 proof. 2. (10 marks) Prove that f(x) 6 ln(x –...

  • Enable Editing (0) PROTECTED VIEW Be careful-files from the Internet can contain viruses. Unless you need...

    Enable Editing (0) PROTECTED VIEW Be careful-files from the Internet can contain viruses. Unless you need to edit it's safer to stay in Protected view K19 DK 1 CD5 - EXCEL Tutorial 3 CURRENT DESIGNS 4 Bill Johnson, sales manager, and Diane Buswell, controller at Current Designs are beginning to analyze the cost 5 considerations for one of the composite models of the kayak division. They have provided the following production 6 and operational costs necessary to produce one composite...

  • // This program displays a menu and asks the user to make a 2 // selection....

    // This program displays a menu and asks the user to make a 2 // selection. An if/else if statement determines which item 3 // the user has chosen. 4 #include <iostream> 5 #include <iomanip> 6 using namespace std; 7 8 int main() 9 { 10 int choice; // To hold a menu choice 11 int months; // To hold the number of months 12 double charges; // To hold the monthly charges 13 14 // Constants for membership rates...

  • Hw#2 (Protect FILE TOOLS VIEW PROTECTED VIEW Be careful-files from the internet can contain vinuses. Unless...

    Hw#2 (Protect FILE TOOLS VIEW PROTECTED VIEW Be careful-files from the internet can contain vinuses. Unless you need to edit, it's safer to stay in Prot 1. An air-standard Otto cycle has a compression ratio of 9.0. At the beginning of compression, p1-100 kPa and T1-300 K. The heat addition per unit mass of air is 1400 kJ/kg. Determine (a) the net work, in kJ per kg of air. (b) the thermal efficiency of the cycle. (e) the maximum temperature...

  • I need help solving this assignment, you are given a full piece of code that does not run correctly. Some of the bugs ca...

    I need help solving this assignment, you are given a full piece of code that does not run correctly. Some of the bugs can be found at compile time, while others are found at run time. Access the UserMenu.cpp code file (in the zip file in Start Here) and use debugging practices and the debugger in Visual Studio to find each bug. Fix the bug and write a comment in the code giving a description of how you found the...

  • Can someone please tell me why the calculation for earnings is not coming through at the...

    Can someone please tell me why the calculation for earnings is not coming through at the end of the program? Thank you. //This program should tell us about streaming services #include <iostream> #include <iomanip> #include <string> using namespace std; int main() {    int choice, streams;    double earnings;    string song;    string artist;    string streamingService;       const int Tidal = 0.01250;    const int Amazon = 0.00402;    const int Apple_Music = 0.00735;    const int...

  • C++ Check Book Program I need to have a checkbook program that uses the following items....

    C++ Check Book Program I need to have a checkbook program that uses the following items. My code that I have appears below. 1) Math operations using built-in math functions 2) Class type in a separate .h file with member functions (accessor functions, get, set, show, display find, etc). There needs to be an overloaded function base/derived classes or a template. 3) Binary File #include <iostream> using namespace std; int main() {     double checking,savings;     cout<<"Enter the initial checking...

  • Х i PROTECTED VIEW Be careful—files from the Internet can contain viruses. Unless you need to...

    Х i PROTECTED VIEW Be careful—files from the Internet can contain viruses. Unless you need to edit, it's safer to stay in Protected View. Enable Editing X 3. (10 marks) Find the limit and prove it using the definition. 4x2 + 13 lim x600 x2 + x + 1 4. (10 marks) Find the limit and prove it using the definition. 4x3 + 13 lim x00x2 + x + 1 sin x 5. (10 marks) Check whether f(x) = if...

  • My if/else statement wont run the program that I am calling. The menu prints but once...

    My if/else statement wont run the program that I am calling. The menu prints but once I select a number the menu just reprints, the function called wont run. What can I do to fix this probelm? #include <iostream> #include "miltime.h" #include "time.h" #include "productionworker.h" #include "employee.h" #include "numdays.h" #include "circle.h" using namespace std; int main() { int select=1;     while (select>0) { cout << "Option 1:Circle Class\n"<< endl; cout << "Option 2:NumDay Class\n" << endl; cout <<"Option 3:Employee and Production...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT