Problem Solving with C++ (10th Edition)
Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134521176
Author: SAVITCH
Publisher: PEARSON
bartleby

Concept explainers

bartleby

Videos

Textbook Question
Book Icon
Chapter 1, Problem 1P

Using your text editor, enter (that is, type in) the C++ program shown in Display 1.8. Be certain to type the first line exactly as shown in Display 1.8. In particular, be sure that the first line begins at the left-hand end of the line with no space before or after the # symbol. Compile and run the program. If the compiler gives you an error message, correct the program and recompile the program. Do this until the compiler gives no error messages. Then run your program.

Expert Solution & Answer
Check Mark
Program Plan Intro

Creation of main method to compute a value and testing the formula

Program Plan:

  • Define the main method.
    • Declare variables for count of pods, count of peas and total peas.
    • Display message to get count of pods.
    • Store value for count of pods.
    • Display message to get count of peas in pods.
    • Store value for count of peas in pods.
    • Compute value for total peas by multiplying both input values.
    • Display the resultant value of total peas.
Program Description Answer

Program Description:

The following java program describes about creation of main method to implement a formula for computing value for total peas.

Explanation of Solution

Program:

//Include library

#include<iostream>

//Use namespace

using namespace std;

//Define main method

int main()

{

//Declare variables

int numberOfPods, peasPerPod, totalPeas;

//Define message

cout<<"Press return after entering a number"<<endl;

//Define message

cout<<"Enter the number of pods"<<endl;

//Store value

cin>>numberOfPods;

//Define message

cout<<"Enter the number of peas in a pod"<<endl;

//Store value

cin>>peasPerPod;

//Compute value

totalPeas = numberOfPods*peasPerPod;

//Define message

cout<<"If you have ";

//Define message

cout<<numberOfPods;

//Define message

cout<<" Peas pods"<<endl;

//Define message

cout<<"and ";

//Display message

cout<<peasPerPod;

//Define message

cout<<" Peas in each pod, then"<<endl;

//Define message

cout<<"You have ";

//Display value

cout<<totalPeas;

//Display message

cout<<" Peas in all the pods";

//Pause console window

system("pause");

//Return

return 0;

}

Sample Output

Press return after entering a number

Enter the number of pods

10

Enter the number of peas in a pod

15

If you have 10 Peas pods

and 15 Peas in each pod, then

You have 150 Peas in all the pods

Press any key to continue . . .

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
Modular Program Structure. Analysis of Structured Programming Examples. Ways to Reduce Coupling. Based on the given problem, create an algorithm and a block diagram, and write the program code: Function: y=xsin⁡x Interval: [0,π] Requirements: Create a graph of the function. Show the coordinates (x and y). Choose your own scale and show it in the block diagram. Create a block diagram based on the algorithm. Write the program code in Python. Requirements: Each step in the block diagram must be clearly shown. The graph of the function must be drawn and saved (in PNG format). Write the code in a modular way (functions and the main part should be separate). Please explain and describe the results in detail.
Based on the given problem, create an algorithm and a block diagram, and write the program code: Function: y=xsin⁡x Interval: [0,π] Requirements: Create a graph of the function. Show the coordinates (x and y). Choose your own scale and show it in the block diagram. Create a block diagram based on the algorithm. Write the program code in Python. Requirements: Each step in the block diagram must be clearly shown. The graph of the function must be drawn and saved (in PNG format). Write the code in a modular way (functions and the main part should be separate). Please explain and describe the results in detail.
Based on the given problem, create an algorithm and a block diagram, and write the program code: Function: y=xsin⁡x Interval: [0,π] Requirements: Create a graph of the function. Show the coordinates (x and y). Choose your own scale and show it in the block diagram. Create a block diagram based on the algorithm. Write the program code in Python. Requirements: Each step in the block diagram must be clearly shown. The graph of the function must be drawn and saved (in PNG format). Write the code in a modular way (functions and the main part should be separate). Please explain and describe the results in detail.

Chapter 1 Solutions

Problem Solving with C++ (10th Edition)

Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
What is Abstract Data Types(ADT) in Data Structures ? | with Example; Author: Simple Snippets;https://www.youtube.com/watch?v=n0e27Cpc88E;License: Standard YouTube License, CC-BY