Download the attached CreateRandomNumbersFile.cpp file, open it in Dev C++, and then compile and run it. The program should generate a file called numbers_lastname.txt in the same folder as the program (replace lastname with your last name).Write a program that asks for the name of an input file. Then, read all the numbers in the file, and display the following information to the screen:count of numbers in the filesum of all numbers in the fileaverage of all numbers in the file (to 2 decimal places)count of numbers in each range (100-199, 200-299, 300-399, etc.)The program should:display a hello messageask the user for an input filedisplay the name of the input filevalidate the file opens correctlydisplay statistical information as shown abovedisplay a goodbye messageSubmit the following back to this assignment (either individually or as a ZIP file):completed CPP file (not the EXE file)file of random numbersCreateRandomNumbersFile contains the following information:/* This program will ask the user for their last name, which will be used for* naming an output file. The output file will consist of 500-999 random* integers, all between 100-999.** COSC-1436 Fundamentals of Programming I* Author: Richard Herschede* Date: 7/23/2019*///LIBRARIES#include <iostream> //for input/output#include <string> //for string functions#include <fstream> //for files#include <cstdlib> //for rand() and srand()#include <ctime> //for system timeusing namespace std;//GLOBAL CONSTANTSconst int MAX_COUNT = 999; //maximum count of numbers to generateconst int MIN_COUNT = 500; //minimum count of numbers to generateconst int MAX_NUM = 999; //maximum value of random numberconst int MIN_NUM = 100; //minimum value of random number//MAIN FUNCTIONint main(){//hellocout << "This program will generate 500-999 random numbers, and write" << endl;cout << "them to a file. The user's last name will determine the name" << endl;cout << "of the output file. Each random number will be between 100-999." << endl << endl;//define local variablesofstream outfile; //output file streamstring username, //user's last namefilename = "numbers_"; //name of output fileint num, //variable to hold random numbercount; //variable to hold count of numbers//get system time and seed random number generatorunsigned seed = time(0);srand(seed);//set file name for output filecout << "Please enter your last name: ";getline(cin,username);filename += username + ".txt";//open the output file (will create new or overwrite existing)outfile.open(filename);//get count of random numbers to generatecount = (rand() % (MAX_COUNT - MIN_COUNT + 1)) + MIN_COUNT;cout << "Generating " << count << " random numbers to file " << filename << endl;//generate random numbers and write them to output filefor (int i = 0; i < count; i++){num = (rand() % (MAX_NUM - MIN_NUM + 1)) + MIN_NUM;outfile << num << " ";} //end for//close the output fileoutfile.close();//goodbyecout << "\nProgram complete. The output file, " << filename << ", is located" << endl;cout << "in the same directory as this program." << endl;return 0;} //end main() Language is C++Keep it in the most simplest form please.

Question
Asked Oct 16, 2019
4 views

Download the attached CreateRandomNumbersFile.cpp file, open it in Dev C++, and then compile and run it. The program should generate a file called numbers_lastname.txt in the same folder as the program (replace lastname with your last name).

Write a program that asks for the name of an input file. Then, read all the numbers in the file, and display the following information to the screen:

  • count of numbers in the file
  • sum of all numbers in the file
  • average of all numbers in the file (to 2 decimal places)
  • count of numbers in each range (100-199, 200-299, 300-399, etc.)

The program should:

  • display a hello message
  • ask the user for an input file
  • display the name of the input file
  • validate the file opens correctly
  • display statistical information as shown above
  • display a goodbye message

Submit the following back to this assignment (either individually or as a ZIP file):

  • completed CPP file (not the EXE file)
  • file of random numbers

CreateRandomNumbersFile contains the following information:

/* This program will ask the user for their last name, which will be used for
* naming an output file. The output file will consist of 500-999 random
* integers, all between 100-999.
*
* COSC-1436 Fundamentals of Programming I
* Author: Richard Herschede
* Date: 7/23/2019
*/

//LIBRARIES
#include <iostream> //for input/output
#include <string> //for string functions
#include <fstream> //for files
#include <cstdlib> //for rand() and srand()
#include <ctime> //for system time
using namespace std;

//GLOBAL CONSTANTS
const int MAX_COUNT = 999; //maximum count of numbers to generate
const int MIN_COUNT = 500; //minimum count of numbers to generate
const int MAX_NUM = 999; //maximum value of random number
const int MIN_NUM = 100; //minimum value of random number

//MAIN FUNCTION
int main()
{
//hello
cout << "This program will generate 500-999 random numbers, and write" << endl;
cout << "them to a file. The user's last name will determine the name" << endl;
cout << "of the output file. Each random number will be between 100-999." << endl << endl;

//define local variables
ofstream outfile; //output file stream
string username, //user's last name
filename = "numbers_"; //name of output file
int num, //variable to hold random number
count; //variable to hold count of numbers

//get system time and seed random number generator
unsigned seed = time(0);
srand(seed);

//set file name for output file
cout << "Please enter your last name: ";
getline(cin,username);
filename += username + ".txt";

//open the output file (will create new or overwrite existing)
outfile.open(filename);

//get count of random numbers to generate
count = (rand() % (MAX_COUNT - MIN_COUNT + 1)) + MIN_COUNT;
cout << "Generating " << count << " random numbers to file " << filename << endl;

//generate random numbers and write them to output file
for (int i = 0; i < count; i++)
{
num = (rand() % (MAX_NUM - MIN_NUM + 1)) + MIN_NUM;
outfile << num << " ";
} //end for

//close the output file
outfile.close();

//goodbye
cout << "\nProgram complete. The output file, " << filename << ", is located" << endl;
cout << "in the same directory as this program." << endl;

return 0;
} //end main()

 

Language is C++

Keep it in the most simplest form please.

check_circle

Expert Answer

Step 1
  • The given CreateRandomNumbersFile.cpp asks the user to enter last name and then creates a txt file containing random numbers.
  • The following C++ program greets the user with Hello message and then asks for the name ...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in
EngineeringComputer Science

Programing Language

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: Write a wholly creative quiz program that consists of three original questions that you make up acco...

A: Error in the program-Remove the points variable after each fragment of code except the point variabl...

question_answer

Q: First, launch NetBeans and close any previous projects that may be open (at the top menu go to File ...

A: Create a JAVA class of name AtmSimulator. Import DecimalFormat class to display balance up to 2 deci...

question_answer

Q: The code you will need for this assignment is here (in C file)   /* YOUR NAME HERE* CSCI 4100* Progr...

A: C shell is a type of command processor which enables user to write and modify commands .It can also ...

question_answer

Q: Oscar has invested a huge amount of money into the stock market and doesn't trust just anyone to giv...

A: Given three variables p, m and z where p=Pain Webster, m=Meg A. Cash and z=LaZora.As per the conditi...

question_answer

Q: Code needed for the following: Use the final numerical grade to look up the corresponding letter gra...

A: This C++ program obey the following rubrics: -In main method – Declaring and initializing the variab...

question_answer

Q: What is the difference between Python and JavaScript coding?

A: JavaScriptIt is a web programing language.it is a cross- platform language.Its code is integrated wi...

question_answer

Q: The effects of lack of computer equipment in academic performance

A: To solve this problem .first of all you need to understand the relationship of computer devices in a...

question_answer

Q: Driving is expensive. Write a program with a car's miles/gallon and gas dollars/gallon (both doubles...

A: Program Instructions:Take car's miles/gallon and gas dollars/gallon as input using scanner class.Cal...

question_answer

Q: The current deficit of Arrakis (a fictional country) is 47000000 grods (a fictional currency). It is...

A: Program Algorithm-STARTStep1: Define a class Calculate.Step2: Write the main function for the class....