Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Dynamic Arrays Dynamic Arrays A company keeps the salary of its employees in a d

ID: 3573742 • Letter: D

Question

Dynamic Arrays

Dynamic Arrays A company keeps the salary of its employees in a database file. Assume that the file contains just numbers. Create an array of doubles to store the salary as you read them one at a time. Now write a programmer defined function to sort the salary in ascending order and display them. Your program should work for a database file of any size. Since we have not learnt how to reallocate dynamic memory, you may have to read the file twice. Use HW7Prob3.txt for your program.

Explanation / Answer

#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
  
   vector<int> numbers;
   ifstream in("input.txt",ios::in);
   int number;
   int count=0;
while (in >> number) {
       numbers.push_back(number);
   }
   in.close();
sort(numbers.begin(),numbers.end(),numbers)
   for (int i=0; i<numbers.size(); i++) {
   cout << numbers[i] << endl;
   }     
}