Question

In: Computer Science

Write C++ programs to perform the following tasks. In the program descriptions below, example input and...

Write C++ programs to perform the following tasks. In the program descriptions below, example input and output is provided. NOTE: You don’t need arrays to solve any of these problems. You should NOT use arrays to solve any of these problems.

• stat.cpp: Let the user input a one or more integers, space separated, on a single line (as seen below), then work out and display the sum, average, sum of squares and population variance of the numbers. Remember, you do not need nor should you use an array to solve this problem.

Enter integers: 2 4 1 3
           Sum: 10.0
       Average: 2.5
Sum of Squares: 30.0
      Variance: 1.25

minmax.cpp: Let the user input a one or more integers, space separated, on a single line (as seen below), then work out and display the largest and smallest values. Remember, you do not need nor should you use an array to solve this problem.

  Enter integers: 1 9 3 7 5 6 4 8 2 10
             Min: 1

Max: 10

numbers.cpp: Write a program that prints out the binary, octal, decimal, and hexadecimal representation (respectively) of all unsigned shorts (in order). If the number is divisible by 3, then also print “Go”. If the number is divisible by 5, then also print “GOGOGO”. Otherwise, “S” should also be printed. Below is a sample of some of the entries near the middle:

  0b1010'0000'0000'0000 0120000 40960 0xa000 GOGOGO
  0b1010'0000'0000'0001 0120001 40961 0xa001 S
  0b1010'0000'0000'0010 0120002 40962 0xa002 Go
  0b1010'0000'0000'0011 0120003 40963 0xa003 S
  0b1010'0000'0000'0100 0120004 40964 0xa004 S
  0b1010'0000'0000'0101 0120005 40965 0xa005 GOGOGOGO

degrees.cpp: Write a program to read a floating point number representing degrees Celsius, and print the equivalent temperature in degrees Fahrenheit. Print your results in a form such that the numbers are represented up to two decimal places.

  Enter in a temperature in Celsius: 100
  100.00 degrees Celsius converts to 212.00 degrees Fahrenheit.

time.cpp: Given as input an integer number of seconds, print as output the equivalent time in hours, minutes and seconds.

  Enter in the number of seconds as an integer: 7322
  7322 seconds is equivalent to 2 hours 2 minutes 2 seconds.

Solutions

Expert Solution

Screenshots of the code:

1)

Sample output:

Code to copy:

//stat.cpp

#include"stdafx.h"

#include<iostream>

using namespace std;

int main()

{

     int n, i, num;

     double squareSum = 0, sum = 0, avg, variance;

     cout << "Enter the number you want to enter: ";

     cin >> n;

     cout << "Enter integers: ";

     for (i = 0; i<n; i++)

     {

          cin >> num;

          sum = sum + num;

          squareSum = squareSum + (num*num);

     }//end of main function

     avg = sum / n;

     variance = (squareSum) / n - avg*avg;

     cout << "Sum: " << sum << endl;

     cout << "Average: " << avg << endl;

     cout << "Sum of squares: " << squareSum << endl;

     cout << "Variance: " << variance << endl;

     system("pause");

     return 0;

}//end of main function

2)

Sample Output:

Code to copy:

//minmax.cpp

#include"stdafx.h"

#include<iostream>

using namespace std;

int main()

{

     int n, minimum = 99999, maximum = -1, i, num;

     cout << "Enter the number you want to enter: ";

     cin >> n;

     cout << "Enter integers: ";

     for (i = 0; i<n; i++)

     {

          cin >> num;

          if (num<minimum)

              minimum = num;

          if (num>maximum)

              maximum = num;

     }

     cout << "Minimum: " << minimum << endl;

     cout << "Maximum: " << maximum << endl;

     system("pause");

     return 0;

}//end of main function

3)

Sample Output:

Code to copy:

//numbers.cpp

#include"stdafx.h"

#include<bitset>

#include<iostream>

using namespace std;

int main()

{

     unsigned int number;

     for (number = 0; number <= 65535; number++)

     {

          cout << "0b" << bitset<16>(number) << "\t";

          cout << std::oct << number << "\t";

          cout << std::dec << number << "\t";

          cout << std::hex << std::showbase << number << "\t";

          if (number % 3 != 0 && number % 5 != 0)

          {

              cout << "S";

          }

          else

          {

              if (number % 5 == 0)

                   cout << "GOGOGO";

              if (number % 3 == 0)

                   cout << "GO";

          }

          cout << endl;

     }

     system("pause");

     return 0;

}

4)

Sample Output:

Code to copy:

//degrees.cpp

#include"stdafx.h"

// degree to fahrenheit

#include<iostream>

#include<iomanip>

using namespace std;

int main()

{

     float cel, fahren;

     cout << "Enter the temperature in celcius: ";

     cin >> cel;

     fahren = (9.0 / 5)*cel + 32;

     cout << fixed << setprecision(2) << cel << " degrees Celcius converts to " << fixed << setprecision(2) << fahren << " degrees Fahrenheit";

     system("pause");

     return 0;

}//end of main function

5)

Sample Output:

Code to copy:

5)

//time.cpp

#include"stdafx.h"

// seconds into hours

#include<iostream>

using namespace std;

int main()

{

     int sec, hr, minute, d;

     cout << "Enter the number of seconds: ";

     cin >> sec;

     d = sec;

     hr = sec / 3600;

     sec = sec % 3600;

     minute = sec / 60;

     sec = sec % 60;

     cout << d << " seconds is equivalent to " << hr << " hours " << minute << " minutes " << sec << " seconds.";

     system("pause");

     return 0;

}//end of main function


Related Solutions

Using the following code perform ALL of the tasks below in C++: ------------------------------------------------------------------------------------------------------------------------------------------- Implementation: Overload input...
Using the following code perform ALL of the tasks below in C++: ------------------------------------------------------------------------------------------------------------------------------------------- Implementation: Overload input operator>> a bigint in the following manner: Read in any number of digits [0-9] until a semi colon ";" is encountered. The number may span over multiple lines. You can assume the input is valid. Overload the operator+ so that it adds two bigint together. Overload the subscript operator[]. It should return the i-th digit, where i is the 10^i position. So the first...
Write a program to perform the following two tasks: 1. The program will accept a string...
Write a program to perform the following two tasks: 1. The program will accept a string as input in which all of the words are run together, but the first character of each word is uppercase. Convert the string to a string in which the words are separated by spaces and only the first word starts with an uppercase letter. For example, the string "StopAndSmellTheRose" would be converted to "Stop and smell the rose". Display the result string. 2. Then...
Write a program to perform the following two tasks: 1. The program will accept a string...
Write a program to perform the following two tasks: 1. The program will accept a string as input in which all of the words are run together, but the first character of each word is uppercase. Convert the string to a string in which the words are separated by spaces and only the first word starts with an uppercase letter. For example, the string "StopAndSmellTheRose" would be converted to "Stop and smell the rose". Display the result string. 2. Then...
Write a Java program named, MultiTable, (MultiTable.java), with the following tasks: Prompt user to input the...
Write a Java program named, MultiTable, (MultiTable.java), with the following tasks: Prompt user to input the maximum number (as integer) Store a multiplication table for all combinations (with some specific eliminations) of value 0 through the maximum number (being entered) into a 2-D array Write a method named printTable to print out the MulitTable, with the following header, public static void printTable(int[][] multitable) In printTable(), when the value of the MultiTable is an odd number, print out Z Must use...
Write a Java program named, TicketSale, (TicketSale.java) with the following tasks: Prompt user to input the...
Write a Java program named, TicketSale, (TicketSale.java) with the following tasks: Prompt user to input the number of Adult tickets to purchase Prompt user to input the number of Children tickets to purchase Prompt user to input the number of Senior tickets to purchase Write a method named, ticketCost(), which will be invoked by main() with statement similar to: cost = ticketCost( adults, children, senior ); Ticket costs structure: $15.00 for each adult $10.00 for each child $5.00 for each...
A C program that will perform the following: Input the string: Abc_3_deF Expected Output: The string...
A C program that will perform the following: Input the string: Abc_3_deF Expected Output: The string you entered is: aBC_Three_DEf An output for just this specific input will be fine. If you want to provide a program for all outputs, it would help with my understanding of how the program works overall as well but it is not needed. Thanks!
Done in C++, Write a program to read the input file, shown below and write out...
Done in C++, Write a program to read the input file, shown below and write out the output file shown below. Use only string objects and string functions to process the data. Do not use c-string functions or stringstream (or istringstream or ostringstream) class objects for your solution. Input File Cincinnati 27, Buffalo 24 Detroit 31, Cleveland 17 Kansas City 24, Oakland 7 Carolina 35, Minnesota 10 Pittsburgh 19, NY Jets 6 Philadelphia 31, Tampa Bay 20 Green Bay 19,...
Description: Write and test a MASM program to perform the following tasks: 1. Display your name...
Description: Write and test a MASM program to perform the following tasks: 1. Display your name and program title on the output screen. 2. Display instructions for the user. 3. Prompt the user to enter two numbers. 4. Calculate the sum, difference, product, (integer) quotient and remainder of the numbers. 5. Display a terminating message. Requirements: 1. The main procedure must be divided into sections:  introduction  get the data  calculate the required values  display the results...
Write a C++ Program Write a program that prompts the user to input a string. The...
Write a C++ Program Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must insert the following comments at the beginning...
Write Lexical Analyzer program in C language. Below is the sample input and ouput. /* output...
Write Lexical Analyzer program in C language. Below is the sample input and ouput. /* output Enter the string: if(a<b){a=10;} Tokens are identifier :if punctuation mark : ( identifier :a operator:< identifier :b punctuation mark : ) punctuation mark : { identifier :a operator:= constant :10 punctuation mark : ; punctuation mark : } */
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT