Question: I need help with 1.cpp program with all parts Program 1.cpp This program will be a modification of 0.cpp. Add the following menu options. Random
I need help with 1.cpp program with all parts
Program 1.cpp
This program will be a modification of 0.cpp. Add the following menu options.
Random ) this option will seed the data.txt file with 50 random int(s) between 0 and 500.
Min ) This will find and print the minimum int.
Max ) this will find and print the maximum int.
Both Min and Max options will print how many intervals it took to find the min or max int.
Data.txt can be any random integer.
here is my 0.cpp file.
#include
#include
using namespace std;
int main()
{
string fileName;
cout << "Enter file name: ";
cin >> fileName;
ifstream infile(fileName);
int num;
ofstream outfile;
if (!infile)
{
cout << "File not Found... ";
return -1;
}
infile.close();
int choice;
do
{
cout << "1. Display numbers 2. Save number to file 3. Exit Enter choice: ";
cin >> choice;
switch (choice)
{
case 1:
infile.open(fileName);
while (infile>>num)
{
cout << num << endl;
}
infile.close();
break;
case 2:
outfile.open(fileName,ios::app);
cout << "Enter number: ";
cin >> num;
outfile < cout << "Data saved." << endl; outfile.close(); break; case 3: cout << "Thanks for using this app..." << endl; break; default: cout << "Wrong choice...Try again." << endl; break; } } while (choice != 3); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
