Starting Out With C++: Early Objects (10th Edition)
Starting Out With C++: Early Objects (10th Edition)
10th Edition
ISBN: 9780135235003
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
bartleby

Concept explainers

Expert Solution & Answer
Book Icon
Chapter 5.7, Problem 5.7CP

A)

Explanation of Solution

Analysis of given code:

The given code is used to print “Hello world” once. The process is carried out using a “do…while” loop. Initially the “count” variable is assigned with a value “3”. The loop executes till the value of “count” is lesser than “1”.

Given code segment:

//Include necessary header file

#include <iostream>

using namespace std;

//Function main

int main()

{

    // Declare and initialize a variable

    int count = 3; //Line 1

    //Loop

    do //Line 2

    { //Line 3

        // Print statement

        cout<<"Hello World...

B)

Explanation of Solution

Analysis of given code:

The given code is used to print value of the variable “val”. The process is carried out using a “do…while” loop. Initially the “val” variable is assigned with a value “5”. The loop executes till the value of “val” is greater than or equal to “5”.

Given code segment:

// Include necessary header file

#include <iostream>

using namespace std;

// Driver function main()

int main()

{

    // Declare and initialize variable

    int val = 5; //Line 1

    //Loop

    do //Line 2

&...

C)

Explanation of Solution

Analysis of given code:

The given code is used to print the value of variables “number” and “count” on the screen. The “do…while” loop is used to increment the value of variable “number” by “2” add the value of variable “count” by “1”.

Given code segment:

// Include necessary header file

#include <iostream>

using namespace std;

// Function main

int main()

{

    // Declare and initialize variables

    int count = 0, number = 0, limit = 4; //Line 1

    //Loop

    do //Line 2

    { //Line 3

        // Increment number by 2

        number+=2; //Line 4

        // Increament count by 1

        count++; //Line 5

    } //Line 6

    //Condition

    while(count < limit); //Line 7

    //Display number and count

    cout << number << " " << count <<endl; //Line 8

    //Return value

    return 0;

}

Explanation:

  • In “Line 1”, declare the variables “count”, “number”, and “limit” and initialize it to “0”, “0”, and “4” respectively...

Blurred answer
Students have asked these similar questions
int main() { int i, salary[10], range[9]={0, 0, 0, 0, 0, 0, 0, 0, 0}; double gross[10], total[10]; string amount[9]={"$200 - $299", "$300 - $399", "$400 - $499", "$500 - $599", "$600 - $699", "$700 - $799", "$800 - $899", "$900 - $999", "$1000 and over"}; for (i=0; i<10; i++){ cout<<"Please enter gross sales of salespeople "<<i+1<<": "; cin>>gross[i]; total[i]=200+(gross[i]*0.09); salary[i]=total[i]; if (salary[i]>=200 && salary[i]<=299) range[0]=range[0]+1; else if (salary[i]>=300 && salary[i]<=399) range[1]=range[1]+1; else if (salary[i]>=400 && salary[i]<=499) range[2]=range[2]+1; else if (salary[i]>=500 && salary[i]<=599) range[3]=range[3]+1; else if (salary[i]>=600 && salary[i]<=699) range[4]=range[4]+1; else if (salary[i]>=700 && salary[i]<=799) range[5]=range[5]+1; else if (salary[i]>=800 && salary[i]<=899) range[6]=range[6]+1; else if (salary[i]>=900…
Q1)Further enhance your program below as follows (include a loop structure): • allow data to be continuously input for more customers • After processing the last customer’s order, display a summary report of sales of the day showing details of total number of customers, a summary of each of the packages sold for the day and the total sales value  #include <stdio.h> #include <stdlib.h> #include<string.h> #pragma warning(disable:4996) int main(void) { // Variable declarations int t = 0; float k, y, u, i; int a, b, c, d; int p; float add, tt, f; char name[30], ic[20]; char addr[50]; //The personal details of customer // printf("\n========================================================================================================\n"); printf("\n Vegetable ordering system\n"); printf("\n========================================================================================================\n"); printf("Please enter your full name :"); scanf(" %[^\n]", &name);…
Solve the Problem with C++ (Financial application: compare loans with various interest rates)Write a program that lets the user enter the loan amount and loan period in number of years and displays the monthly and total payments for each interest rate starting from 5% to 8%, with an increment of 1/8.Sample RunLoan Amount: 10000Number of Years: 5Interest Rate Monthly Payment Total Payment5.000% 188.71 11322.745.125% 189.28 11357.135.250% 189.85 11391.59...7.875% 202.17 12129.978.000% 202.76 12165.83

Chapter 5 Solutions

Starting Out With C++: Early Objects (10th Edition)

Ch. 5.8 - You want to write a for loop that displays I love...Ch. 5.8 - Prob. 5.12CPCh. 5.8 - Write a for loop that displays your name 10 times.Ch. 5.8 - Write a for loop that displays all of the odd...Ch. 5.8 - Write a for loop that displays every fifth number,...Ch. 5.8 - Write a for loop that sums up the squares of the...Ch. 5.8 - Write a for loop that sums up the squares of the...Ch. 5.8 - Write a for loop that repeats seven times, asking...Ch. 5.8 - Write a for loop that calculates the total of the...Ch. 5.11 - Which loop (while, do-while, or for) is best to...Ch. 5.11 - How many total stars will be displayed by each of...Ch. 5.11 - What will the following program segment display?...Ch. 5.12 - Prob. 5.24CPCh. 5.12 - What header file must be included in a program to...Ch. 5.12 - What five steps must be taken when a file is used...Ch. 5.12 - What is the difference between a text file and a...Ch. 5.12 - Prob. 5.28CPCh. 5.12 - What type of file stream object do you create if...Ch. 5.12 - What type of file stream object do you create if...Ch. 5.12 - If dataFi1e is an of stream object associated with...Ch. 5.12 - If dataFile is an ifstream object associated with...Ch. 5.12 - Assume you have an output file named numbers.txt...Ch. 5 - To _______ a value means to increase it by one.Ch. 5 - To _______ a value means to decrease it by one.Ch. 5 - Prob. 3RQECh. 5 - Prob. 4RQECh. 5 - The statement or block that is repeated is known...Ch. 5 - Each repetition of a loop is known as a(n)...Ch. 5 - A loop that evaluates its test expression before...Ch. 5 - A loop that evaluates its test expression after...Ch. 5 - A loop that does not have a way of stopping is...Ch. 5 - A(n) ______ is a variable that counts the number...Ch. 5 - Prob. 11RQECh. 5 - A(n) ________ is a variable that is initialized to...Ch. 5 - A(n) ______ is a special value that marks the end...Ch. 5 - The ________ loop is ideal for situations that...Ch. 5 - The _____ loop always iterates at least once.Ch. 5 - The _______and ______ loops will not iterate at...Ch. 5 - Inside the for loops parentheses, the first...Ch. 5 - A loop that is inside another is called a(n)...Ch. 5 - The _________ statement causes a loop to terminate...Ch. 5 - The _____ statement causes a loop to skip the...Ch. 5 - What header file do you need to include in a...Ch. 5 - What data type do you use when you want to create...Ch. 5 - What happens if you open an output file and the...Ch. 5 - What data type do you use when you want to create...Ch. 5 - What is a files read position? Where is the read...Ch. 5 - What should a program do when it is finished using...Ch. 5 - Write a do-while loop that asks the user to enter...Ch. 5 - Write a for loop that displays the following set...Ch. 5 - Write a loop that asks the user to enter a number....Ch. 5 - Write a nested loop that displays the following...Ch. 5 - Rewrite the following code, converting the while...Ch. 5 - Rewrite the following code, replacing the do-while...Ch. 5 - Convert the following whi1e loop to a for loop:...Ch. 5 - Convert the following for loop to a while loop:...Ch. 5 - Complete the program segment below to write the...Ch. 5 - Complete the following program segment that reads...Ch. 5 - What will each of the following program segments...Ch. 5 - int x = 1 ; while (x 10) x++; cout x;Ch. 5 - Each of the program segments in this section has...Ch. 5 - A) // This code should use a loop to raise a...Ch. 5 - A) // This code should display the sum of two...Ch. 5 - Prob. 46RQECh. 5 - Characters for the ASCII Codes Write a program...Ch. 5 - Sum of Numbers Write a program that asks the user...Ch. 5 - Distance Traveled The distance a vehicle travels...Ch. 5 - Celsius to Fahrenheit Table In one of the Chapter...Ch. 5 - Speed Conversion Chart Write a program that...Ch. 5 - Ocean Levels Assuming the level of the Earths...Ch. 5 - Circle Areas The formula to compute the area of a...Ch. 5 - Pennies for Pay Write a program that calculates...Ch. 5 - Weight Loss If moderately active persons cut their...Ch. 5 - Calories Burned Running on a particular treadmill,...Ch. 5 - Membership Fees Increase A country club, which...Ch. 5 - Random Number Guessing Game Write a program that...Ch. 5 - Random Number Guessing Game Enhancement Enhance...Ch. 5 - The Greatest and Least of These Write a program...Ch. 5 - Student Line-Up A teacher has asked all her...Ch. 5 - Rate of Inflation The annual rate of inflation is...Ch. 5 - Population Write a program that will predict the...Ch. 5 - Math Tutor Version 3 This program started in...Ch. 5 - Hotel Suites Occupancy Write a program that...Ch. 5 - Rectangle Display Write a program that asks the...Ch. 5 - Diamond Display Write a program that uses nested...Ch. 5 - Triangle Display Write a program that uses nested...Ch. 5 - Arrowhead Display Write a program that uses nested...Ch. 5 - Sales Bar Chart Write a program that asks the user...Ch. 5 - Savings Account Balance Write a program that...Ch. 5 - Using FilesTotal and Average Rainfall Write a...Ch. 5 - Using FilesPopulation Bar Chart Write a program...Ch. 5 - Using FilesStudent Line Up Modify the Student...Ch. 5 - Using FilesSavings Account Balance Modification...
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
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning