answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
kramer
2 years ago
5

Need help with this C++ question

Computers and Technology
1 answer:
sertanlavr [38]2 years ago
4 0

Answer:

Here is the improvement of the program:

#include<iostream>  //to use input output functions

using namespace std;// to identify objects like cin cout

int main()  {   //start of main function

  string pet;         // "cat" or "dog"  

  char spayed;       // 'y' or 'n'      

  // Get pet type and spaying information  

cout << "Enter the pet type (cat or dog): ";   //prompts user to enter pet type

  cin  >> pet;   //reads input pet type

  if(pet=="cat"|| pet=="dog")     {   //use OR operator to check the type

  cout << "Has the pet been spayed or neutered (y/n)? ";   //prompts user to input if pet been spayed or neutered

  cin  >> spayed;}   //reads input spayed value

  else   // display the message below

  cout<<"only cats and dogs need pet tags";        

  // Determine the pet tag fee  

if (pet == "cat")   //if type of pet is cat

  {  if (spayed == 'y' || spayed == 'Y')  //lowercase or upper case y is accepted  

        cout << "Fee is $4.00 \n";   //if spayed is y or Y

     else   //if spayed is not y or Y

        cout << "Fee is $8.00 \n";   }  

  else if (pet == "dog")   //if type is dog

  {  if (spayed == 'y' || spayed=='Y')   //if spayed is y or Y

        cout << "Fee is $6.00 \n";  

     else   //if spayed is not y or Y

        cout << "Fee is $12.00 \n";    }        

  return 0;   }

 

Explanation:

Step 1:

Here is the copy of original source code:

#include <iostream>

using namespace std;

int main() {

string pet;

char spayed;

cout <<"Enter the pet type (cat or dog): ";

cin >> pet;

cout <<"Has the pet been spayed or neutered (y/n)?" ;

cin >>spayed;

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";

return 0; }

Step 2:

Compile the program and then run it 7 times

Run       Input Data         Fee Information                                      Correct

 1                cat y               Fee is $4.00                                           Yes  

 2               cat n               Fee is $8.00                                           Yes    

 3               cat Y               Fee is $8.00                                           No

 4               dog y              Fee is $6.00                                           Yes

 5               dog n              Fee is $12.00                                         Yes

 6               dog Y              Fee is $12.00                                         No

 7              hamster n        Only cats and dogs need pet tags       Yes                

Step 3:            

See the Answer section

OR logical operator is used so that either a lowercase 'y' or an uppercase 'Y is accepted:

if (spayed == 'y' || spayed == 'Y')

program only execute the spay/neuter prompt and input when the pet type is cat or dog:

if(pet=="cat"|| pet=="dog")  

 {     cout << "Has the pet been spayed or neutered (y/n)? ";    

cin  >> spayed; }    

else    

cout<<"only cats and dogs need pet tags";      

Step 4:

Run       Input Data         Fee Information                                      Correct

 1                cat y               Fee is $4.00                                           Yes  

 2               cat n               Fee is $8.00                                           Yes    

 3               cat Y               Fee is $4.00                                           Yes

 4               dog y              Fee is $6.00                                           Yes

 5               dog n              Fee is $12.00                                         Yes

 6               dog Y              Fee is $6.00                                           Yes

 7              hamster         Only cats and dogs need pet tags          Yes  

In the last input hamster the program does not ask for spayed information. It only asks to Enter the pet type. When the user enters hamster the program displays the message: Only cats and dogs need pet tags.

You might be interested in
Which of the following statements is incorrect? An operating system provides an environment for the execution of programs. An op
rosijanka [135]

Answer:

command line and graphical user interface

Explanation:

there were (and still are) operating system with no graphical user interface at all, as for example some Unix releases

8 0
1 year ago
Under what category of programs and apps do databases and enterprise computing fall?
Evgesh-ka [11]
Answer is productivity

Sometimes called the office or personal productivity software, productivity software is dedicated to producing databases, spreadsheets, charts, graphs, documents, graphs, digital video and worksheets. Reason behind the name productivity is due to the fact that it increases productivity in office work.

6 0
1 year ago
What elements of SANS 20 you could leverage to reduce the TCP/IP vulnerabilities of your workstation
Vlada [557]

Answer:

- limitation and control of network ports, protocols and services.

- Continuous vulnerability assessment and remediation.

Explanation:

The TCP or transmission control protocol is a layer 4 protocol (transport), that reliably transports packets in sequential segments to an application in the destination computer, using the ip address and the port number of the application.

The ICMP sent during the TCP/ip activities, can render the network vulnerable to attacks. limitation and control of the network ports, protocols and services and continuous assessment would mitigate the vulnerability of the TCP/ip model.

5 0
1 year ago
An administrator has initiated the process of deploying changes from a sandbox to the production environment using the Force IDE
Pani-rosa [81]

Option A because the environment should be selected for which the changes are to be applied. In a time Force IDE has many project environments for example maybe a java project and C++ project would be there on sandbox, so the environment selection is important.

Option B because the related changed sets should be specified so that other developers that have access to the project can see the changes being made.

Option D The data fields that are needed to be deployed should also be provided so that the updated version can be seen by other developers.

Rejected Options :

Option C user name and password has nothing to do with the production environment because if the user has it only then it can come and make changes.

6 0
1 year ago
Lance is at a bus station. His friend is using the ATM machine to withdraw some money. Lance notices a stranger deceptively watc
Blababa [14]

Answer:

The person watching Lances friend typing the ATM pin is an example of <u>"shoulder browsing"</u> and Lances friend should <u>"Change the ATM pin."</u>

<u />

<u>I hope this is the answer you were looking for!</u>

8 0
1 year ago
Read 2 more answers
Other questions:
  • Linda is making handouts for her upcoming presentation. She wants the handouts to be comprehensible to people who do not attend
    12·2 answers
  • ____ is a program placed on a computer without the user's knowledge that secretly collects information about the user
    14·1 answer
  • In which of these places might you be most likely to find a peer-to-peer network? On the Internet In a hospital In a home In a l
    5·2 answers
  • A ____ resembles a circle of computers that communicate with each other.
    14·1 answer
  • In cell B16, enter a function to calculate the total attendance for the years 2014 through 2018 using the totals in the range B1
    10·1 answer
  • Topological sort requires only a tiny addition to the DFS algorithms. Exactly one of the following data structures is required t
    9·1 answer
  • Lin is booting up his computer, and during the boot process, the computer powers down. After several unsuccessful attempts to bo
    12·1 answer
  • Your employer, yPlum Corporation is manufacturing two types of products: Mirabelle smartphone, and Blackamber laptop. The compan
    14·1 answer
  • Two devices are connected to the Internet and communicating with one another. A squirrel chews through one of the wires in the n
    6·1 answer
  • A shop will give discount of 10% if the cost of purchased quantity is more than 1000. Ask user for quantity suppose, one unit wi
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!