Concept explainers
Using your text editor, enter (that is, type in) the C++
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:
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;
}
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?
Chapter 1 Solutions
Problem Solving with C++ (10th Edition)
Additional Engineering Textbook Solutions
Introduction To Programming Using Visual Basic (11th Edition)
SURVEY OF OPERATING SYSTEMS
Starting Out with Python (4th Edition)
Database Concepts (8th Edition)
Mechanics of Materials (10th Edition)
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
- Create a standard C++ program wherein it satisfies the following objectives 1.Create a menu. (Under the menu, it should display the following) *Testing *Information *Exit note: create a loop link between the menu and the program will only stop if the user chooses "exit". 2.I will provide the codes under the testing menu and it's up to you if you want to improve it a little further. 3. Under the information menu, the program will then ask the user for its name, address, age, and current relationship status, be creative and you can add small simple features to the program itself. Thanks a lot! Here's our first version program under the testing menu #include <iostream>using namespace std; int main() { bool hasFever; bool hasCough; bool breathingProblem; char input; cout << "WELCOME TO COVID-19 TRACKER \n \n" ; cout << "Does the patient have fever? (y/n) "; cin >> input; if (input == 'y' || input == 'Y') { hasFever =…arrow_forwardPlease rewrite the C++ code below according to the instructions and criteria. Please replace the if statement according to the last criteria highligthed in bold. Thank you. Instructions; Replace as many conditional statements in the 12 Days Of Christmas song with one or more arrays. Criteria compilation - the program compiles without error the first switch statement - replace the first switch statement with an array the second switch statement - replace the second switch statement with an array the if statement - rewrite the inner for loop by replacing the if statement and other statements in the inner for loop with references to these arrays:int last[] {-1, 0, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12};int first[] {-1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; Expert Answers: Step 1 I have stored the values that are printed by 1st switch case statement in an array a. Similarly I have stored the values that are printed by 2st switch case statement in an array b. Then I removed the switch…arrow_forwardI need help to my project 2 programming C++. Please Project 2 is a continuation of Project 1. Modify the code from Project 1 in the following ways: Step 1: Add code to prompt the user to enter the name of the room that they are entering information for. Validate the input of the name of the room so that an error is shown if the user does not enter a name for the room. The user must be given an unlimited amount of attempts to enter a name for the room. Step 2: Add Input Validation to the code using the following rules: The length of the room cannot be less than 5 feet The width of the room cannot be less than 5 feet The user's menu selection for the amount of shade should be 1, 2, or 3. If the user's input is invalid, the program should display an appropriate error message and prompt the user to re-enter their input. The user must be given an unlimited amount of attempts to enter valid input. Step 3: Add code to have the program ask the user if they would like to enter…arrow_forward
- Please answer: You are tasked to create a program on C++ that will enable the user to input first name, middle initial, and last name all in upper cases. with a 22-character limit that also includes spaces in between the names on the ID card. The following limitations should be included in the program:1.) If the first name, second name, middle initial, and last name exceed the character limit, use the first name initial and last name. 2.) If the last name’s character count is greater than or equal to the character limit, omit the second name and middle initial. Use the first name initial and truncate the last name to fit the character limit. 3.) The spaces in between the first name, second name, middle initial, and last name should not be included in the input. 4.) If there is no second name or middle initial, input 0. OUTOUT PROGRAM SHOULD BE: Type First Name: Type Second Name: Type Middle Name: Type Last Name: Result:arrow_forwardC++ Programming. I need to develop my original code. Please help me write a C++ code following this instructions: (Please write your own code, not copy other contents please) The company needs a more detailed report to be generated at the end of each shift. The sample screen output with the report is listed below: Welcome to CTC Taxi. Do you need a taxi? Y Taxi CTC0001 will pick you up in a few minutes. (Taxi CTC0001 determined that there were 3 passengers) Do you need a taxi? Y Taxi CTC0004 will pick you up in a few minutes. (Taxi CTC0004 determined that there were 5 passengers) …… …… Do you need a taxi? N CTC Taxi served a total of 124 passengers today. CTC0001 CTC00022 CTC0003 CTC0004 CTC0005 CTC0006 19 Calls 25 Calls 10 Calls 12 Calls 22 Calls 13 Calls 25 Passengers 45 Passengers 34 Passengers 29 Passengers 24 Passengers 30…arrow_forwardC++ Programming It should align exactly like the screenshot, sample output. The local Driver’s License Office has asked you to write a program that grades the written portion of the driver’s license exam. The exam has 20 multiple choice questions. Here are the correct answers: 1. A2. D3. B4. B5. C6. B7. A8. B9. C10.D11. A12. C13. D14. B15. D16. C17. C18. A19. D20. B Your program should store the correct answers shown above in an array. It should ask the user to enter the student’s answers for each of the 20 questions, and the answers should be stored in another array. After the student’s answers have been entered, the program should display a message indicating whether the student passed or failed the exam. (A student must correctly answer 15 of the 20 questions to pass the exam.) It should then display the total number of correctly answered questions, the total number of incorrectly answered questions, and a list showing the question numbers of the incorrectly answered questions.…arrow_forward
- C++ Problem: show code and steps Please and thank you. Recall the Temperature Program we created in Slide Set 01, Challenge Problem 01. Write a function that converts a temperature amount in Fahrenheit to Kelvin. Additionally, throw an error when the temperature entered is below 0ºK (i.e., absolute zero, the lowest possible temperature in the universe). Additionally, use try/catch to properly handle the thrown error to prevent the throw statement from crashing the program. Temperature Equivalencies 0ºK = -273.15ºC = -459.67ºFarrow_forwardThese to two screenshots are ONE SINGLE assignment. If you cannot complete this assignment in full, do not answer this question. If, however, you do plan on building a program using C++ based on the instructions from these two screenshots, then please continue. Thank you for your understanding. When you are done, join all your programs together and present the user with a menu so they can select which one they want to run.arrow_forwardNeed help figuring out this program and typing it in c++.arrow_forward
- Please do not copy and paste the answer that Chegg has for this question. I have asked this question already and the expert copied and pasted the answer from Chegg. Please actually solve this problem, or I'll just have to cancel my Bartleby subscription. C++ Question Hello, Please create the correct code based on the attached requirement picture. Please make sure the code is functional. Please do not use any Advanced C++ syntax. Thank you.arrow_forwardBy using C++ programming language, please provide the source code, screenshot of the program output and flowchart thanks.arrow_forwardc++ You are working for a software firm that developped a word processor. A common error users often make is that they forget the caps locks on and print text like this: ”tHIS IS A SAMPLE of an error”, this usually happens at the beginning of a new sentence(i.e. right afer a dot or in a new line). Write a program to detect this error and fix it. The input will be a long string on keyboard.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education