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...
#include <iostream> #include <iomanip> using namespace std; int main() {             float miles;   //miles traveled          &nbsp
#include <iostream> #include <iomanip> using namespace std; int main() {             float miles;   //miles traveled             float hours;   //time in hours             float milesPerHour; //calculated miles per hour             cout << "Please input the Miles traveled" << endl;             cin >> miles;             cout << "Please input the hours traveled" << endl;             cin >> hours;                         milesHours = miles / hours; cout << fixed << showpoint << setprecision(2);             cout << "Your speed is " <<...
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 <cstring> #include <stdio.h> #include <iostream> using namespace std; int main() {        const int...
#include <cstring> #include <stdio.h> #include <iostream> using namespace std; int main() {        const int SIZE = 20;     char str[SIZE];     char str1[SIZE];     int n;     int k =1;        printf("Enter a word: \n");     fgets(str,SIZE,stdin);     printf("Enter another word: \n");     fgets(str1,SIZE,stdin);        if (str1[strlen(str1) - 1] == '\n')     {         str1[strlen(str1)-1] = '\0';     }     if (str[strlen(str) - 1] == '\n')     {         str[strlen(str)-1] = '\0';     }      ...
#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 "lib.hpp" using namespace std; int main() {    // declare the bool bool...
#include <iostream> #include "lib.hpp" using namespace std; int main() {    // declare the bool bool a = true; bool b= true;    //Print the Conjunction function cout<<"\n\nConjunction Truth Table -"<<endl; cout<< "\nP\tQ\t(P∧Q)" <<endl; cout<< a <<"\t"<< b <<"\t"<< conjunction(a,b) <<endl; cout<< a <<"\t"<< !b <<"\t"<< conjunction(a,!b) <<endl; cout<< !a <<"\t"<< b <<"\t"<< conjunction(!a,b) <<endl; cout<< !a <<"\t"<< !b <<"\t"<< conjunction(!a,!b)<<endl;    //Print the Disjunction function cout<<"\n\nDisjunction Truth Table -"<<endl; cout<< "\nP\tQ\t(PVQ)" <<endl; cout<< a <<"\t"<< b <<"\t"<< disjunction(a,b) <<endl;...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT