Reverse.cpp
Write a program that reads in a series of positive integers terminted by a -1, e.g.
73 95 61 21 90 85 14 78 -1
The values should be stored in an array. The program then prints the values in reverse order as well as the average (to one decimal place). For example,
Please enter the integers: 73 95 61 21 90 85 14 78 -1
The values in reverse order are
78 14 85 90 21 61 95 73
The average is 64.6
You must use a function for computing the reverse, passing the array as an argument. Thus the function header will be similar to
void reverse(int[] A);
NOTE: The program standards are given below:
1. Program Header . In addition to you name and project number, include a brief description of the program functionality in the header comment for the program
2. Variables and Constants. All variables and constants in a program must be declared at the beginning of the program
3. Initialization. Variables may not be initialized in their declaration.
4. Printing of if-then. Use one of the following
if (expression) statement
if (expression)
Single-statement
if (expression) {
Multiple-statements
}
5. Printing of if-then-else. Use one of the following
if (expression) statement
else statement
if (expression)
Single-statement
else
Single-statement
if (expression) {
Multiple-statements
} else {
Multiple-statements
}
6. Printing of while loops. Use one of the following
while (expression) statement
while (expression)
Single-statement
while (expression) {
Multiple-statements
}
7. For loops. The bodies of all for-loops must be indented at least 3 (but no more than 5) spaces:
for(int i = 0; i < n; i++) {
cout << "Enter the number:" << flush;
cin >> num;
if (num < 0) num_neg++;
else if (num > 0) num_pos++;
else num_zero++;
}
8. Methods. The bodies of all functions must be indented at least 3 (but no more than 5) spaces:
double CircleArea(double r) {
const double Pi = 3.1415;
return Pi * r * r;
}
#include <iostream>
#include <iomanip>
using namespace std;
void reverse(int A[], int size){
for(int i = 0; i < size / 2; i++){
int temp = A[i];
A[i] = A[size - i - 1];
A[size - i - 1] = temp;
}
}
int main(){
int arr[1000], count = 0;
double average = 0.0;
cout << "Please enter the integers: ";
while(true){
cin >> arr[count];
if(arr[count] == -1) break;
count++;
}
reverse(arr, count);
cout << "The values in reverse order are\n\t";
for(int i = 0; i < count; i++){
cout << arr[i] << " ";
average += arr[i];
}
average /= count;
cout << fixed << setprecision(1);
cout << "\nThe average is " << average <<
endl;
}
Reverse.cpp Write a program that reads in a series of positive integers terminted by a -1,...
C++ Write a program that reads three positive integers (> 0) from the command line (one at a time), then computes and prints the smallest entered number. Use if-else statements for three integer comparison. Example: Enter an integer: 5 Enter an integer: 23 Enter an integer: 7 The smallest number is: 5 Example 2: Enter an integer: 3 Enter an integer: 3 Enter an integer: 6 The smallest number is: 3 "The input must be positive number. The program should...
Write a c++ expression representing the following algebraic expression. Assume that all variables in your program are of the type double and that your program has already included the <cmath> header file. 3x + 1/y - 10 + Squareroot g Your answer: (b) Rewrite the same expression assuming that variables x and y in your program are of type int your answer: Convert the following switch statement into an equivalent if-else if statement switch (ch) {case 'A'; cout << "...
Write a program which: Prints out the Multiplication Table for a range of numbers (positive integers). Prompts the user for a starting number: say 'x' Prompts the user for an ending number: say 'y' Prints out the multiplication table of 'x' up to the number 'y' Sample outputs include: SPECIFIC REQUIREMENTS You must use the following method to load the array: public static void loadArray(int table[ ][ ], int x, int y) You must use the following method to...
C++ Write a program that asks user to input three positive integers one at a time, then compute and output the largest entered number. Use if-else statements for three integer comparison and use for loops for a user validation. Example output: Enter an integer: -7 Invalid! Number must be positive. Enter an integer: -2 Invalid! Number must be positive. Enter an integer: 5 Enter an integer: 7 Enter an integer: 1 Largest number: 7
program. 13. What's the output of the following program? #include< iostream> #include&math> using namespace std; int p 7; void main) extern double var int p abs(-90); system( "pause"); double var = 55; 14. How many times does "#" print? forlint i 0;j< 10; +ti) if(i-2141 6) continue; cout<< "#"; 15. Write the function declaration/prototype for a, pow function b floor function 16. State True or False a. b. c. d. e. isupper function returns a double value for loop is...
Write a program to calculate students’ average test scores and their grades. You may assume the following data: Johnson 85 83 77 91 76 Aniston 80 90 95 93 48 Cooper 78 81 11 90 73 Gupta 92 83 30 69 87 Blair 23 45 96 38 59 Clark 60 85 45 39 67 Kennedy 77 31 52 74 83 Bronson 93 94 89 77 97 Sunny 79 85 28 93 82 Smith 85 72 49 75 63 Use three...
Write a program to calculate students’ average test scores and their grades. You may assume the following data: Johnson 85 83 77 91 76 Aniston 80 90 95 93 48 Cooper 78 81 11 90 73 Gupta 92 83 30 69 87 Blair 23 45 96 38 59 Clark 60 85 45 39 67 Kennedy 77 31 52 74 83 Bronson 93 94 89 77 97 Sunny 79 85 28 93 82 Smith 85 72 49 75 63 Use three...
Microsoft Visual Studios 2017 Write a C++ program that computes a student’s grade for an assignment as a percentage given the student’s score and total points. The final score must be rounded up to the nearest whole value using the ceil function in the <cmath> header file. You must also display the floating-point result up to 5 decimal places. The input to the program must come from a file containing a single line with the score and total separated by...
Write a JAVA program with methods that initializes an array with 20 random integers between 1 and 50 and then prints four lines of output, containing 1)The initialized array. 2)Every element at an even index. 3)Every even element. 4)All elements in reverse order. Requirements (and hints): 1. Build a method that takes any integer array as input and prints the elements of the array. ALL printing in this lab must be done using a call to the printArray method and...
The second project involves completing and extending the C++ program that evaluates statements of an expression language contained in the module 3 case study. The statements of that expression language consist of an arithmetic expression followed by a list of assignments. Assignments are separated from the expression and each other by commas. A semicolon terminates the expression. The arithmetic expressions are fully parenthesized infix expressions containing integer literals and variables. The valid arithmetic operators are +, –, *, /. Tokens...