Questions
Programing lanugaue is C++ Purpose of code: Plan and code a menu-driven modular program utilizing an...

Programing lanugaue is C++

Purpose of code:
Plan and code a menu-driven modular program utilizing an array

An input file has an unknown number of numeric values(could be empty too).Read the numbers from the input fileand store even numbers in one arrayand odd numbers in another array.Create menu options to

Display count of even numbers, count of odd numbersand the sum values in each array
Determine the average of each array
Determine the median of each array
Sort each array in ascending order(use bubble sort) and output results to a file
Display X number of the highest values(for example, 3 highest values) in each array.Ask a user for the number of the highest values
Display X number of the lowest values(for example, 7 lowest values) in each array.Ask a user for the number of the lowest values
A user should be able to run many as many times as a user wants
Notes :

Clearly label all output
Use switch statement to implement the menu
Watch put for array boundaries.C would not do it for you.
You only need to create one function to determine the average.Just call it twice to determine the average of each array.The same applies to the rest of the menu options.
A user should be able to run the menu as many times as a user wants
Thoroughly test your program.Your grade partially depends on the quality of your test data.
Must comply with the posted guidelinesand standards
Well document your code(comments)

Question: Is it possible to rewirte this code with the same purpose but without the Vector function? Is is possible to make a small edits or will I have to rewrite the whol code? Can someone show me how rewrite the code without a vector function?

#include<iostream>
#include<fstream>
#include<string>
#include<vector>
#include<iomanip>
using namespace std;

void sort(vector<int>& nums);
double getMedian(vector<int> nums);
vector<int> readFile(string filename);
void displayMenu();

int main()
{
string filename = "input.txt";
vector<int> allNums = readFile(filename);
vector<int> allEvens, allOdds;
for (int i = 0; i < allNums.size(); i++)
{
if (allNums[i] % 2 == 0)
allEvens.push_back(allNums[i]);
else
allOdds.push_back(allNums[i]);
}
int choice;
cout << setprecision(2) << fixed;

do
{
displayMenu();
cin >> choice;
switch (choice)
{
case 1:
{
int sumEven = 0, sumOdd = 0;
for (int i = 0; i < allEvens.size(); i++)
sumEven += allEvens[i];
for (int i = 0; i < allOdds.size(); i++)
sumOdd += allOdds[i];
cout << "\nCount of even numbers = " << allEvens.size() << endl << "Count of odd numbers = " << allOdds.size() << endl;
cout << "Sum of all even numbers = " << sumEven << endl << "Sum of all odd numbers = " << sumOdd << endl;
break;
}
case 2:
{
int sumEven = 0, sumOdd = 0;
for (int i = 0; i < allEvens.size(); i++)
sumEven += allEvens[i];
for (int i = 0; i < allOdds.size(); i++)
sumOdd += allOdds[i];
double avgEven = 0.0, avgOdd = 0.0;
avgEven = (double)sumEven / (double)allEvens.size();
avgOdd = (double)sumOdd / (double)allOdds.size();
cout << "\nAverage of all even numbers = " << avgEven << endl << "Average of all odd numbers = " << avgOdd << endl;
break;
}
case 3:
{
cout << "\nMedian of all the even numbers = " << getMedian(allEvens) << endl << "Median of all the even numbers = " << getMedian(allOdds) << endl;
break;
}
case 4:
{
string outFileName;
cout << "\nEnter the output filename: ";
cin >> outFileName;
sort(allEvens);
sort(allOdds);
ofstream outFile(outFileName.c_str());
if (!outFile.is_open())
{
cout << "Error in opening " << outFileName << "! Exiting..\n";
exit(EXIT_FAILURE);
}
outFile << "Sorted array of Evens:\n";
for (int i = 0; i < allEvens.size(); i++)
outFile << allEvens[i] << endl;
outFile << "\nSorted array of Odds:\n";
for (int i = 0; i < allOdds.size(); i++)
outFile << allOdds[i] << endl;
cout << "Sorted array successfully written to " << outFileName << ".\n";
break;
}
case 5:
{
sort(allEvens);
sort(allOdds);
int XEven, XOdd;
// EVEN
cout << "\nHow many highest numbers do you want to display for the even numbers array? ";
cin >> XEven;
while (XEven < 1 || XEven > allEvens.size())
{
cout << "Please enter a value between 1 & " << allEvens.size() << "!\n";
cout << "How many highest numbers do you want to display for the even numbers array? ";
cin >> XEven;
}
cout << XEven << " highest number(s) in the even array: ";
for (int i = XEven; i > 0; i--)
{
cout << allEvens[i] << " ";
}
// ODD
cout << "\nHow many highest numbers do you want to display for the odd numbers array? ";
cin >> XOdd;
while (XOdd < 1 || XOdd > allOdds.size())
{
cout << "Please enter a value between 1 & " << allOdds.size() << "!\n";
cout << "How many highest numbers do you want to display for the odd numbers array? ";
cin >> XOdd;
}
cout << XOdd << " highest number(s) in the odd array: ";
for (int i = XOdd; i > 0; i--)
{
cout << allOdds[i] << " ";
}
cout << endl;
break;
}
case 6:
{
sort(allEvens);
sort(allOdds);
int XEven, XOdd;
// EVEN
cout << "\nHow many lowest numbers do you want to display for the even numbers array? ";
cin >> XEven;
while (XEven < 1 || XEven > allEvens.size())
{
cout << "Please enter a value between 1 & " << allEvens.size() << "!\n";
cout << "How many lowest numbers do you want to display for the even numbers array? ";
cin >> XEven;
}
cout << XEven << " lowest number(s) in the even array: ";
for (int i = 0; i < XEven; i++)
{
cout << allEvens[i] << " ";
}
// ODD
cout << "\nHow many lowest numbers do you want to display for the odd numbers array? ";
cin >> XOdd;
while (XOdd < 1 || XOdd > allOdds.size())
{
cout << "Please enter a value between 1 & " << allOdds.size() << "!\n";
cout << "How many lowest numbers do you want to display for the odd numbers array? ";
cin >> XOdd;
}
cout << XOdd << " lowest number(s) in the odd array: ";
for (int i = 0; i < XOdd; i++)
{
cout << allOdds[i] << " ";
}
cout << endl;
break;
}
case 0:
{
cout << "\nThanks..Goodbye!\n";
exit(EXIT_SUCCESS);
}
default:
cout << "\nInvalid selection!\n";
}
cout << endl;
} while (choice != 0);
return 0;
}
void sort(vector<int>& nums)
{
int n = nums.size();
for (int i = 0; i < n - 1; i++)
{
for (int j = 0; j < n - i - 1; j++)
{
if (nums[j] > nums[j + 1])
{
int temp = nums[j];
nums[j] = nums[j + 1];
nums[j + 1] = temp;
}
}
}
}
double getMedian(vector<int> nums)
{
int n = nums.size();
sort(nums);
if (n % 2 == 0)
return (double)nums[n / 2];
return (double)(nums[(n - 1) / 2] + nums[n / 2]) / 2.0;
}
vector<int> readFile(string filename)
{
vector<int> allNums;
ifstream inFile(filename.c_str());
string line;
if (!inFile.is_open())
{
cout << "Error in opening " << filename << "! Exiting..\n";
exit(EXIT_FAILURE);
}
while (getline(inFile, line))
{
allNums.push_back(stod(line));
}
inFile.close();
return allNums;
}
void displayMenu()
{
cout << "Choose from the following options:\n1. Count of even numbers, count of odd numbers and sum values in each array\n2. Average of each array\n3. Median of each array\n" <<
"4. Sort each array in ascending order\n5. Display X numbers of the highest values in each array\n6. Display X numbers of the lowest values in each array\n0. Exit\nYour selection >> ";
}

In: Computer Science

Consider the street in Idaho City, with 5000 families looking for a new tent. Each family’s...

Consider the street in Idaho City, with 5000 families looking for a new tent. Each family’s maximum willingness to pay for a tent is $120. In addition to the price at the store, each family bears a cost of $20 per mile to transport the tent home. Suppose there is a single tent seller on this street, Camping Gears, CG, and CG is planning to open new branches in this camping town along this street. CG has a constant unit cost of $40 per tent, and the fixed cost of opening a new branch is $2000.

(a) If CG wants to set a price low enough to serve all 5000 families, what is the highest price it can set if CG will have 1 branch? 2 branches? 3 branches? What is the highest price it can set if CG will have n branches?

(b) Write CG’s profit function with n branches and find the optimal number of branches if CG wants to serve all families.

(c) What is the total transportation cost paid by all customers when CG has only one branch? 2 branches? 3 branches? What is the total transportation cost paid by all customers when CG has n branches?

(d) Write the cost minimization problem for the sum of the total transportation and set-up costs. Solve for the optimal number of branches that maximizes total surplus.

In: Economics

Two dice are rolled one after the other. Find the probability that the sum of the...

Two dice are rolled one after the other. Find the probability that the sum of the dots on the dice total is a number greater than 11 if the second die is a 5.

In: Statistics and Probability

2 dice are rolled 8 times in a row. What is the probability that the combined...

2 dice are rolled 8 times in a row. What is the probability that the combined number of 4 will not come up more than 2 times in 8 rolls?

In: Statistics and Probability

The probability that a person has 20-20 vision is 0.13 The class is 40 students. What...

The probability that a person has 20-20 vision is
0.13 The class is 40 students. What is the mean and the Standard deviation of the number with 20-20 vision in the class.

In: Statistics and Probability

A spinner has 8 equal sections numbered 1 to 8. what is the probability of th...

A spinner has 8 equal sections numbered 1 to 8. what is the probability of th spinner stopping on a number that is a multiple of 3 or is greater than 5?

In: Statistics and Probability

Give the expected value, variance, and probability distribution for the sum of a fair coin and...

Give the expected value, variance, and probability distribution for the sum of a fair coin and a random real number chosen uniformly in the range [ -1, 1]. Sketch the PMF.

In: Math

(15.30) It appears that people who are mildly obese are less active than leaner people. One...

(15.30) It appears that people who are mildly obese are less active than leaner people. One study looked at the average number of minutes per day that people spend standing or walking. Among mildly obese people, the mean number of minutes of daily activity (standing or walking) is approximately Normally distributed with mean 370 minutes and standard deviation 68 minutes. The mean number of minutes of daily activity for lean people is approximately Normally distributed with mean 526 minutes and standard deviation 108 minutes. A researcher records the minutes of activity for an SRS of 8 mildly obese people and an SRS of 8 lean people.

Use z-scores rounded to two decimal places to answer the following:

What is the probability (±±0.0001) that the mean number of minutes of daily activity of the 8 mildly obese people exceeds 420 minutes?

What is the probability (±±0.0001) that the mean number of minutes of daily activity of the 8 lean people exceeds 420 minutes?

In: Statistics and Probability

In Lotto649, a player selects 6 numbers with replacement from the integers 1 through 49, inclusive....

In Lotto649, a player selects 6 numbers with replacement from the integers 1 through 49, inclusive. In the actual game, the order of the selection of numbers does not matter. In other words, if the winning lottery number for the week is (2, 17, 29, 8, 10, 3), then any permutations of this set of 6 numbers will also be considered a ‘winning ticket’.

a) How many unique lottery numbers are there? Include point-form explanations of you are counting this.

b) What is the probability of winning the lottery if you know that all 6 numbers of the winning number this week are different?

c) What is the probability of winning the lottery if you know that there are three pairs of doubles in this week’s winning number? Include point-form explanations of how you are counting the number of ways to get three pairs of doubles. Note that the number (1, 1, 1, 1, 1, 1) would be considered 6 of a kind, rather than three pairs of doubles. Similarly, (1, 1, 2, 2, 2, 2) would be classified as a double and a quadruple.

In: Statistics and Probability

Q1. There are ten customers and two cafes A and B. Customers want to purchase from...

Q1. There are ten customers and two cafes A and B. Customers want to purchase from the cafe with fewer customers. A customer’s payoff when purchasing from cafe A is −mA, where mA is the number of customers excluding herself purchasing from A. A customer’s payoff when purchasing from cafe B is −mB, where mB is the number of customers excluding herself purchasing from B. a. Find a pure-strategy Nash equilibrium of this game. Prove that it is a Nash equilib- rium. b. Suppose each player chooses cafe A with probability 1/2 and cafe B with probability 1/2. Show that this is a (mixed-strategy) Nash equilibrium. c. Compare the expected number of customers for each cafe in the pure-strategy and mixed-strategy Nash equilibria. (Remember to show all working)

In: Economics