Question

In: Computer Science

Using C++ 1. Create a main function in a main.cpp file. The main function should look...

Using C++

1. Create a main function in a main.cpp file. The main function should look as follows int main() {return 0;}

2. Create an array.

3. Ask user to enter numbers in size of your array.

4. Take the numbers and store them in your array.

5. Go through your array and add all the numbers.

6. Calculate the average of the numbers.

7. Display the numbers, sum and average.

Solutions

Expert Solution

#include <iostream>

using namespace std;

// 1. Create a main function in a main.cpp file. The main function should look as follows int main() {return 0;}
int main() {
    //2. Create an array.
    int *arr;

    //3. Ask user to enter numbers in size of your array.
    int size;
    cout << "Enter size of array: ";
    cin >> size;

    //4. Take the numbers and store them in your array.
    arr = new int[size];
    cout << "Enter " << size << " integers: ";
    for (int i = 0; i < size; ++i) {
        cin >> arr[i];
    }

    //5. Go through your array and add all the numbers.
    int sum = 0;
    for (int i = 0; i < size; ++i) {
        sum += arr[i];
    }

    //6. Calculate the average of the numbers.
    double average = sum / (double) size;

    //7. Display the numbers, sum and average.
    cout << "Array: ";
    for (int i = 0; i < size; ++i) {
        cout << arr[i] << " ";
    }
    cout << endl << "Sum: " << sum << ", Average: " << average << endl;
    return 0;
}

Related Solutions

Create a CodeBlocks project with a main.cpp file. Submit the main.cpp file in Canvas. C++ Language...
Create a CodeBlocks project with a main.cpp file. Submit the main.cpp file in Canvas. C++ Language A Game store sells many types of gaming consoles. The console brands are Xbox, Nintendo, PlayStation. A console can have either 16 or 8 gigabytes of memory. Use can choose the shipping method as either Regular (Cost it $5) or Expedite (Cost is $10) The price list is given as follows: Memory size/Brand Xbox Nintendo PlayStation 16 gigabytes 499.99 469.99 409.99 8 gigabytes 419.99...
URGENT: USING C++: You are given a main.cpp and a Schedule.h file. You are to write...
URGENT: USING C++: You are given a main.cpp and a Schedule.h file. You are to write a Schedule.cpp file that implements the missing pieces from Schedule.h. // ************************************ // ************* main.cpp ************ // ************************************ #include "Schedule.h" void main() { Schedule s1(10); s1.addEntry(1,20,"Feed Cat"); s1.addEntry(2,40,"Feed Dog"); s1.addEntry(2,50,"Walk Dog"); s1.addEntry(4,0, "Fix Dinner"); s1.addEntry(5,15,"Eat Dinner"); s1.printSchedule(); Schedule s2(s1); // Note this uses the copy constructor cout << endl << "Output from s2 " << endl; s2.printSchedule(); } // ********************************************** // ************* Schedule.h ******************...
Create this C++ program using classes 1. Create a file text file with a string on...
Create this C++ program using classes 1. Create a file text file with a string on it 2. Check the frecuency of every letter, number and symbol (including caps) 3. Use heapsort to sort the frecuencys found 4. Use huffman code on the letters, symbols or numbers that have frecuencys I created the file, and the frecuency part but i'm having trouble with the huffman and heapsort implementation.
please use text only! Instructions Consider the provided C++ code in the main.cpp file: The function...
please use text only! Instructions Consider the provided C++ code in the main.cpp file: The function func2 has three parameters of type int, int, and double, say a, b, and c, respectively. Write the definition of func2 so that its action is as follows: Prompt the user to input two integers and store the numbers in a and b, respectively. If both of the numbers are nonzero: If a >= b, the value assigned to c is a to the...
C++ exercise: The statements in the file main.cpp are in incorrect order. using namespace std; #include...
C++ exercise: The statements in the file main.cpp are in incorrect order. using namespace std; #include <iostream> int main() { string shape; double height; #include <string>    cout << "Enter the shape type: (rectangle, circle, cylinder) "; cin >> shape; cout << endl;    if (shape == "rectangle") { cout << "Area of the circle = " << PI * pow(radius, 2.0) << endl;    cout << "Circumference of the circle: " << 2 * PI * radius << endl;...
Create a shell in C language 1) Create an argument tokenizer then write a main() function...
Create a shell in C language 1) Create an argument tokenizer then write a main() function that prints a prompt inputed by user, accepts input, and tokenizes the input. 2) Use the argument vector to an executeCmd() function with int executeCmd(char **args); 3) The function should return a -1 if an error, or a zero otherwise. Inputing an “x” in the prompter will exit the program. 4) Write an executeCmd() function that can execute any program in the background and...
C++ Recursion, Change the delete_node function in the header file to a recursive delete_node function, main...
C++ Recursion, Change the delete_node function in the header file to a recursive delete_node function, main is already set. Hint: It might be helpful to modify the function so that it uses a separate recursive function to perform whatever processing is needed. //////////////////////////////////////////////////////////////header.h////////////////////////////////////////////////////////////////////////////////////////////// #ifndef HEADER_H_ #define HEADER_H_ #include <iostream> using namespace std; template <class T> class LL { private:    struct LLnode    {        LLnode* fwdPtr;        T theData;    };    LLnode* head; public:    LL();...
In C++ You will create 3 files: The .h (specification file), .cpp (implementation file) and main...
In C++ You will create 3 files: The .h (specification file), .cpp (implementation file) and main file. You will practice writing class constants, using data files. You will add methods public and private to your BankAccount class, as well as helper methods in your main class. You will create an arrayy of objects and practice passing objects to and return objects from functions. String functions practice has also been included. You have been given a template in Zylabs to help...
Create a new project called Lab05b. Keep the main file named main. Write a function readAndPrint,...
Create a new project called Lab05b. Keep the main file named main. Write a function readAndPrint, and power with parameters noted below in the Functions.h file. //Your Last Name #ifndef FUNCTIONS_H #define FUNCTIONS_H #include <fstream> #include <iostream> #include <string> using namespace std; /*reads from a file and prints every item to the screen*/ // file contains sets of //int //string //Don't forget to use infile.ignore() between << and getline //ifstream must be passed by reference void readAndPrint(ifstream &infile); //uses a...
Create a c++ program with this requirements: Create an input file using notepad ( .txt )...
Create a c++ program with this requirements: Create an input file using notepad ( .txt ) . When testing your program using different input files, you must change the filename inside your program otherwise there will be syntax errors. There are a finite number of lines to be read from the data file. But we can’t assume to know how many before the program executes; so, the standard tactic is to keep reading until you find the “End of File”...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT