Question

C++ programming by Malik D. S. 7th edition 5-1: Programs model life programs are models of...

C++ programming by Malik D. S. 7th edition

5-1: Programs model life

programs are models of processes that occur in life. iteration is no exception. look around and find examples of looping processes that you encounter outside of your programming class. for examples, consider the instructions on the back of your shampoo bottle. lather, rinse, repeat. or consider the instructions on the back of the cake mix box: stir 100 times or until batter is smooth. what other examples of loops can you find?

5-2: counting with loops

write a program that inputs a number greater than or equal to 0. the program should then count from 0 to the number inputted using a for-loop, a while-loop, and a do...while loop.

if the user's input is not greater than or equal to 0, display an error message and require the user to try again until they get it right.

5-3: vote tally continued

in assignment 4-4, had created a program to tally votes. the results of the vote are contained in the input file votes.dat.

modify your program to use a loop to read through and process each record in the file votes.dat. the program should summarize the vote data to include a total tally of "yes" and "no" votes, as well as a break-down of votes based on the voter's district. your program should work regardless of the number of records contained within the file.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1: other looping examples are - like opening laptop - press power button to on - eneter password - perform task - shut down -again press power button to on etc.

2.

 #include<iostream> using namespace std; int main() { int num; int count=0; //enter the number by for loop for(count=0;count<1;count++) { cin>>num; if(num<=0) { count=0; cout<<"error , please try again"<<endl; } else { cout<<"number input by for loop"<<endl; } } count=0; //enter the number by while loop while(count==0) { cin>>num; if(num<=0) { count=0; cout<<"error , please try again"<<endl; } else { count++; cout<<"number input by while loop"<<endl; } } count=0; //eneter the number by do while loop do { cin>> num; if(num<=0) { count=0; cout<<"error , please try again"<<endl; } else { count++; cout<<"number input by do while loop"<<endl; } } while(count==0); } 

3. although assignment 4.4 is not give here but as per my understanding this is related to file handling so i am giving soluting for file handling

since you had not specifies format of file so i had done only with yes and no count, you can manipulate it according if needed.

 #include <iostream> #include <string> #include <fstream> #include<vector> int main() { using namespace std; ifstream file("file.txt"); vector<string>arr; if(file.is_open()) { while(file.good()) { string s; file >>s; arr.push_back(s); } } int yes=0,no=0; for(int i=0;i<arr.size();i++) { if(arr[i]=="yes") { yes=yes+1; } else if(arr[i]=="no") { no=no+1; } } cout<<"count of yes "<<yes<<" and count of no "<<no<<endl; } 
Add a comment
Know the answer?
Add Answer to:
C++ programming by Malik D. S. 7th edition 5-1: Programs model life programs are models of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C programming (not c++) This programs input is a series of words. All words consist of...

    C programming (not c++) This programs input is a series of words. All words consist of only lowercase letters(a-z), no uppercase letters or digits or punctuation or other special symbols. The program reads until end-of-file, and then prints out the lowercase letters that were not seen in the input. Enter your input: the quick brown fox jumps over the lazy old dog Missing letters: enter your input: roll tide missing letters: a b c f g h j k m...

  • Arrays Arravs Introduction Your ninth programming assignment will consist of two C++programs. Your programs should compile...

    Arrays Arravs Introduction Your ninth programming assignment will consist of two C++programs. Your programs should compile correctly and produce the specified output. Please note that your programs should comply with the commenting and formatting rules we discussed in class. Please see the descriptive ile on eLearning for details. Program 1- Linear Search Algorithm In Computer Science, it is often very important to be able to locate a specific data item inside a list or collection of data. Algorithms that perform...

  • Programming in C with comments/steps 1. Overview The purpose of this assignment is to give you...

    Programming in C with comments/steps 1. Overview The purpose of this assignment is to give you some experience with writing functions that take in arguments and return values, as well as writing a program that consists of multiple files. This assignment also requires the use of a switch statement, in addition to more practice with printf& scanf declaring variables, using loops, and using logical expressions. For this assignment, you will prompt the user in the main function to enter their...

  • This is done in c programming and i have the code for the programs that it wants at the bottom i ...

    This is done in c programming and i have the code for the programs that it wants at the bottom i jut dont know how to call the functions Program 2:Tip,Tax,Total int main(void) {    // Constant and Variable Declarations    double costTotal= 0;    double taxTotal = 0;    double totalBill = 0;    double tipPercent = 0;    // *** Your program goes here ***    printf("Enter amount of the bill: $");    scanf("%lf", &costTotal);    printf("\n");    // *** processing ***    taxTotal = 0.07 * costTotal;    totalBill...

  • ELEC 1520 Homework - Integer Operations, Selection Statements Instructions Write C++ programs to solve the following...

    ELEC 1520 Homework - Integer Operations, Selection Statements Instructions Write C++ programs to solve the following two problems. Upload your source code files to Canvas. The file names must be of the form coins_your_name.cpp and bonus_your_name.cpp for problems 1 and 2, respectively. Substitute your first and last name for "your_name" in the file name. Problem Statements 1. Given a value V in cents, you need to make change using a minimum number of coins. Assume you have an infinite supply...

  • Exercises (No programming is required. Your submission should be a word or pdf document.) Question 1:...

    Exercises (No programming is required. Your submission should be a word or pdf document.) Question 1: (3 Marks) Convert from binary the number (11081181), to decimal and show all steps. Question 2: (3 Marks) Convert from decimal (350)e to binary and show all steps Question 3: (3 Marks) Convert from decimal (3567)s to hexadecimal and show all steps. Question 4: (3 Marks) Convert from hexadecimal (45AC)s to octal and show all steps Question 5: (2 Marks) Given the following snippet...

  • This C++ Programs should be written in Visual studio 2017 PROGRAM 1: Comparing Using Arrays to...

    This C++ Programs should be written in Visual studio 2017 PROGRAM 1: Comparing Using Arrays to Using Individual Variables One of the main advantages of using arrays instead of individual variables to store values is that the program code becomes much smaller. Write two versions of a program, one using arrays to hold the input values, and one using individual variables to hold the input values. The programs should ask the user to enter 10 integer values, and then it...

  • Kindly follow the instructions provided carefully. C programming   Project 6, Program Design One way to encrypt...

    Kindly follow the instructions provided carefully. C programming   Project 6, Program Design One way to encrypt a message is to use a date’s 6 digits to shift the letters. For example, if a date is picked as December 18, 1946, then the 6 digits are 121846. Assume the dates are in the 20th century. To encrypt a message, you will shift each letter of the message by the number of spaces indicated by the corresponding digit. For example, to encrypt...

  • Introduction to C Programming – COP 3223 1. To learn how to use arrays to store...

    Introduction to C Programming – COP 3223 1. To learn how to use arrays to store and retrieve data to help solving problems. 2. Reinforce use of input files. Introduction: Ninja Academy Ninjas are awesome! Your friend has not stopped talking about how cool ninjas and how they would like to become a ninja. To amuse your friend, you have decided to create a series of programs about ninjas. Problem: Mentorship (ninjamentors.c) It is time for your friend to select...

  • C PROGRAMMING Introduction In this part, you will solve a problem described in English. Although you...

    C PROGRAMMING Introduction In this part, you will solve a problem described in English. Although you may discuss ideas with your classmates, etc., everyone must write and submit their own version of the program. Do NOT use anyone else’s code, as this will result in a zero for you and the other person! Shipping Calculator Speedy Shipping Company will ship your package based on the weight and how far you are sending the package, which can be anywhere in the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT