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 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();...
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”...
Write a C++ program to create a text file. Your file should contain the following text:...
Write a C++ program to create a text file. Your file should contain the following text: Batch files are text files created by programmer. The file is written in notepad. Creating a text file and writing to it by using fstream: to write to a file, you need to open thew file as write mode. To do so, include a header filr to your program. Create an object of type fsrteam. Open the file as write mode. Reading from a...
Create a c++ program that: Create an input file using notepad ( .txt ). When testing...
Create a c++ program that: 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” marker. Input date...
Using C++ Create the UML, the header, the cpp, and the test file for an ArtWork...
Using C++ Create the UML, the header, the cpp, and the test file for an ArtWork class. The features of an ArtWork are: Artist name (e.g. Vincent vanGogh or Stan Getz) Medium (e.g. oil painting or music composition) Name of piece (e.g. Starry Night or Late night blues) Year (e.g. 1837 or 1958)
C++ If you tried to compile a source file that doesn't contain a main() function, would...
C++ If you tried to compile a source file that doesn't contain a main() function, would this error be detected by the preprocessor, the compiler, or the linker? Briefly justify your answer. Hint: think about how the files that don't have main() get processed in a project with multiple files. Alternatively, try it out and look at the error message you get.
This class should include .cpp file, .h file and driver.cpp (using the language c++)! Overview of...
This class should include .cpp file, .h file and driver.cpp (using the language c++)! Overview of complex Class The complex class presents the complex number X+Yi, where X and Y are real numbers and i^2 is -1. Typically, X is called a real part and Y is an imaginary part of the complex number. For instance, complex(4.0, 3.0) means 4.0+3.0i. The complex class you will design should have the following features. Constructor Only one constructor with default value for Real...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT