Problem Solving with C++ (10th Edition)
Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
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
Create a C++ student enrollment system using classes and objects. The program should ask the student for their details (name, gender, address), choose from the list which course they want to take, display their tuition fee, and ask them if they want to apply for a scholarship (if yes, it displays scholarship choices, if no, the program ends). code can only include the basic input and output, the different if statements, switch statement, void function, loop, and of course, classes and objects. please include pseudocodes in every line with detailed explanation. also, please just screenshot the code so it'd be easier to read. thank you.
Write a C++ program based on the design you created in Exercise 2a and name it NameSort.cpp. Step through the code by hand. // Enter your name as a comment for program identification // Program assignment NameSort.cpp // Enter your class section, and time // /* The program NameSort.cpp is a program that prompts the user to enter three names separated by blanks. The names are displayed in alphabetical order. */ /* The user will input three names separated by blanks. */ /* The names will be displayed in alphabetical order. */ //header files // use the correct preprocessor directives for input/output and strings ------------------------- --------------------------- ------------------------ int main() { // declare variables /* declare 3 string variables to read in the three names */ --------------------------------------------- // // prompt the user for three names --------------------------------------------- // read in the three names ----------------------------------------------- // //…
For this C++ Program, help me identify the following: A brief description of the code What is the purpose of the code Explain the codes and how it is used to execute the program   CODE PROBLEM:Write a program that prompts the user to enter 10 names, each with a maximum of 30 characters. Output the names that start with the letter A and its corresponding length.

Chapter 1 Solutions

Problem Solving with C++ (10th Edition)

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
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
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
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