Question

In: Computer Science

complete the program #include <cstdlib> #include <iostream> #include <iomanip> using namespace std; int main(int argc, char**...

complete the program

#include <cstdlib>
#include <iostream>
#include <iomanip>
using namespace std;
int main(int argc, char** argv)
{
int number, sum, count;
// Write a while loop that reads a number from the user and loop
// until the number is divisible by 7
cout << "What is the number? "; cin >> number; while ( ... ) { ... }
cout << number << " is divisible by 7!! << endl << endl;
// Write a for loop that counts down from 10 to 0
// Write a for for loop that adds up all the numbers from 1 to 512
// Write a while loop that reads numbers from the user. Each number must be
// between 0 and 100 (inclusive). The loop ends when the user enters -99.
// Print the average of all the numbers. sum = count = 0;
cout << "Enter number between 0 and 100: "; cin >> number;
while ( ... ) { if (number ... || number ... )
cout << "Not in the range. Skipping" << endl;
else { // count the number of entries and the total sum. ... }
cout << "Enter number between 0 and 100: "; cin >> number;
}
cout << "The average is:" << fixed << setprecision(2) << float(sum) / count << endl; return 0;

Solutions

Expert Solution

#include <cstdlib>
#include <iostream>
#include <iomanip>
using namespace std;
int main(int argc, char** argv)
{
int number, sum, count;
// Write a while loop that reads a number from the user and loop
// until the number is divisible by 7
cout << "What is the number? "; cin >> number; while ( number%7!=0 ) { cout << "What is the number? "; cin >> number; }
cout << number <<" is divisible by 7!! "<<endl;
// Write a for loop that counts down from 10 to 0
count=0;
//counting from 10 down to 0
for(int i=10;0<=i;i--)
{
cout<<i<<endl;//prints i value, remove it ,if you don't need it
count+=1;
}cout<<"The count of numbers 10 down to 0 is:"<<count<<endl;
// Write a for for loop that adds up all the numbers from 1 to 512
sum=0;
for(int i=1;i<=512;i++)
sum+=i;//adding to sum
cout<<"The sum of values from 1 to 512:"<<sum<<endl;
// Write a while loop that reads numbers from the user. Each number must be
// between 0 and 100 (inclusive). The loop ends when the user enters -99.
// Print the average of all the numbers. sum = count = 0;
sum=count=0;
cout << "Enter number between 0 and 100: "; cin >> number;
while ( number!=-99 ) { if (number <0 || 100<number )
{
cout << "Not in the range. Skipping" << endl;
}
else
{
sum+=number;
count+=1;}
cout << "Enter number between 0 and 100: "; cin >> number;

}
cout << "The average is:" << fixed << setprecision(2) << float(sum) / count << endl;


return 0;
}

output:

What is the number? 1
What is the number? 10
What is the number? 14
14 is divisible by 7!!
10
9
8
7
6
5
4
3
2
1
0
The count of numbers 10 down to 0 is:11
The sum of values from 1 to 512:131328
Enter number between 0 and 100: 200
Not in the range. Skipping
Enter number between 0 and 100: -10
Not in the range. Skipping
Enter number between 0 and 100: 10
Enter number between 0 and 100: 20
Enter number between 0 and 100: 30
Enter number between 0 and 100: -99
The average is:20.00


Process exited normally.
Press any key to continue . . .


Related Solutions

Complete the following program #include<iostream> #include<iomanip> #include<fstream> using namespace std; int main() { // I -...
Complete the following program #include<iostream> #include<iomanip> #include<fstream> using namespace std; int main() { // I - Declaring a five by five array /* II - Read data from data.txt and use them to create the matrix in the previous step*/    // III - Count and print the number of even integers in the matrix. /* IV - Calculate and print the sum of all integers in the columns with an even index value. Please note the column index begins...
#include <iostream> #include <iomanip> using namespace std; int main() {     int studentid, numberreverse[20], count =...
#include <iostream> #include <iomanip> using namespace std; int main() {     int studentid, numberreverse[20], count = 0, maximum = 0, minimum = 0;     cout << "Enter your student ID number: ";     cin >> studentid;     cout << "Student ID Number = " << studentid << endl;     while (studentid != 0)     {          numberreverse[count] = studentid % 10;          if (count == 0)          {              minimum = numberreverse[count];              maximum = minimum;          }          else...
What would the following program output? #include <iostream> using namespace std; int main() { char alpha...
What would the following program output? #include <iostream> using namespace std; int main() { char alpha = 'A'; for(int i = 0; i < 13; i++){ for(int j = 0; j < 2; j++){ cout << alpha; alpha++; } } cout << endl; return 0; }
#include <iostream> #include <string> #include <iomanip> #include <cstdlib> #include "Contact.h" using namespace std; class Contact {...
#include <iostream> #include <string> #include <iomanip> #include <cstdlib> #include "Contact.h" using namespace std; class Contact { public: Contact(string init_name = "", string init_phone = "000-000-0000"); void setName(string name); void setPhone(string phone); string getName()const; string getPhone()const; friend ostream& operator << (ostream& os, const Contact& c); friend bool operator == (const Contact& c1, const Contact& c2); friend bool operator != (const Contact& c1, const Contact& c2); private: string name, phone; }; Contact::Contact(string init_name, string init_phone) { name = init_name; phone = init_phone;...
write the algorithm for this the code?!. #include<iostream> using namespace std; #include<string.h> int main() { char...
write the algorithm for this the code?!. #include<iostream> using namespace std; #include<string.h> int main() { char plain[50], cipher[50]="", decrypt[50]=""; int subkeys[50], len;       cout<<"Enter the plain text:"<<endl; cin>>plain;    cout<<"Enter the first subkey:"<<endl; cin>>subkeys[0];    _strupr(plain);    len = strlen(plain);    /**********Find the subkeys**************/    for(int i=1; i<len; i++) { if ((plain[i-1]>='A') && (plain[i-1]<='Z')) { subkeys[i] = plain[i-1]-65; } }    /****************ENCRYPTION***************/       for(int i=0; i<len; i++) { if ((plain[i]>='A') && (plain[i]<='Z')) {    cipher[i] = (((plain[i]-65)+subkeys[i])%26)+65; }...
I want Algorithim of this c++ code #include<iostream> using namespace std; int main() { char repeat...
I want Algorithim of this c++ code #include<iostream> using namespace std; int main() { char repeat = 'y'; for (;repeat == 'y';){ char emplyeename[35]; float basic_Salary,EPF, Dearness_Allow, tax, Net_Salary , emplyee_id; cout << "Enter Basic Salary : "; cin >> basic_Salary; Dearness_Allow = 0.40 * basic_Salary; switch (01) {case 1: if (basic_Salary <= 2,20,00) EPF = 0; case 2: if (basic_Salary > 28000 && basic_Salary <= 60000) EPF = 0.08*basic_Salary; case 3: if (basic_Salary > 60000 && basic_Salary <= 200000)...
#include <iostream> using namespace std; int main() {     int hour;     int min;     for (hour = 1;...
#include <iostream> using namespace std; int main() {     int hour;     int min;     for (hour = 1; hour <= 12; hour++)     {         for (min = 0; min <= 59; min++)         {             cout << hour << ":" << min << "AM" << endl;         }     }       return 0; } 1.      Type in the above program as time.cpp. Add a comment to include your name and date. Compile and run. 2.      What is the bug or logic error in the above program? Add the...
#include <iostream> #include <string> #include <fstream> #include <vector> #include <sstream> using namespace std; int main() {...
#include <iostream> #include <string> #include <fstream> #include <vector> #include <sstream> using namespace std; int main() { ifstream infile("worldpop.txt"); vector<pair<string, int>> population_directory; string line; while(getline(infile, line)){ if(line.size()>0){ stringstream ss(line); string country; int population; ss>>country; ss>>population; population_directory.push_back(make_pair(country, population)); } } cout<<"Task 1"<<endl; cout<<"Names of countries with population>=1000,000,000"<<endl; for(int i=0;i<population_directory.size();i++){ if(population_directory[i].second>=1000000000){ cout<<population_directory[i].first<<endl; } } cout<<"Names of countries with population<=1000,000"<<endl; for(int i=0;i<population_directory.size();i++){ if(population_directory[i].second<=1000000){ cout<<population_directory[i].first<<endl; } } } can u pls explain the logic behind this code up to 10 lines pls, many thanks
#include <stdio.h> #include <unistd.h> #include <stdlib.h> int main(int argc, char **argv) { int count; if ((argc...
#include <stdio.h> #include <unistd.h> #include <stdlib.h> int main(int argc, char **argv) { int count; if ((argc != 2) || (sscanf(argv[1],"%d",&count) != 1)) { fprintf(stderr,"Usage: %s <integer>\n", argv[0]); exit(1); } pid_t pid1, pid2; while (count > 0) { pid1 = fork(); if (pid1 > 0) { pid2 = fork(); count = count - 2; } else if (pid1 == 0) { count = count - 1; } } exit(0); } Question #1 [2 pts] If the command-line argument passed to this...
C++ Given Code: #include <iostream> #include <string> using namespace std; int main() { //declare variables to...
C++ Given Code: #include <iostream> #include <string> using namespace std; int main() { //declare variables to store user input bool cont = true; //implement a loop so that it will continue asking until the user provides a positive integer // the following provides ONLY part of the loop body, which you should complete { cout <<"How many words are in your message? \n"; cout <<"Enter value: "; // get user input integer here    cout <<"\nInvalid value. Please Re-enter a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT