Question

2019/Midterm At Unknown University, the Admissions department has discovered that the best applicants usually go to...

2019/Midterm

At Unknown University, the Admissions department has discovered that the best applicants usually go to bigname

schools instead and the worst often do poorly in courses, so the school wants to concentrate recruitment

efforts and financial aid resources on the middle half of the applicants. You must write a c++ program that takes a

file containing a list of applicants, in which each applicant has a total SAT score, and prints a list of the middle

half of these applicants. (Eliminate the best quarter and the worst quarter). This can be done using a simple

iterative technique. First, read the data from a file named apply.txt into an array of integers (let N be the total

number of applicants). This begin a loop that eliminates applicants one at a time, until only half are left. Within

this loop, let first be a pointer to the first array element that is still included, last be a pointer to the last one,

and r (the number of remaining) be initialized to N. Each time around the loop, either first is incremented or last

is decremented and r decreases by 1. At each step,

a. If r is even, find the remaining applicant with the lowest SAT score and swap it with the applicant at

first. Then increment first, decrement r, and repeat.

b. If r is odd, find the remaining applicant with the highest SAT score and swap it with the applicant at last.

Then decrement last and r and repeat.

c. Quit when r <= N/2. Return the values of first and r.

When only half the applicants are left, write the sorted list to a user-specified output file.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main()
{
   int n = 0;
int first,last,temp;
int arr[100],a[100];
string filename;
ifstream File;
File.open("apply.txt");
while(!File.eof())
{
File>>arr[n];
n++;
}
File.close();
   int r=n;
first=0;
last=n-1;
while(r>n/2)
{
   if(r%2==0)
   {
       int small=arr[0];
       for(int i=1;i<n;i++)
       {
           if(small>arr[i])
           small=i;
           }
           temp=arr[small];
           arr[small]=arr[first];
           arr[first]=temp;
           ++first;
           --r;
       }
       else
       {
           int large=arr[0];
       for(int i=1;i<n;i++)
       {
           if(large<arr[i])
           large=i;
           }
           temp=arr[large];
           arr[large]=arr[last];
           arr[last]=temp;
           --last;
           --r;
       }
   }
   for(int i=first;i<last;i++)
   {
       for(int j=i+1;j<last;j++)
       {
           if(arr[j]<arr[i])
           {
               temp=arr[j];
               arr[j]=arr[i];
               arr[i]=temp;
           }
       }
   }
   ofstream outputfile;
   cout<<"Enter the name of the output file: ";
   getline(cin,filename);
outputfile.open(filename.c_str());
   for(int i=first;i<last;i++)
   {
       outputfile<<arr[i]<<"\n";
   }
outputfile.close();
n=0;
ifstream File1;
File1.open(filename.c_str());
cout<<"The output file contains: ";
while(!File1.eof())
{
File1>>a[n];
n++;
}
for(int i=0;i<n-1;i++)
   {
       cout<<"\n"<<a[i]<<" ";
   }
   File1.close();
return 0;
}

Add a comment
Know the answer?
Add Answer to:
2019/Midterm At Unknown University, the Admissions department has discovered that the best applicants usually go to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • A test harness program for testing sorting methods is provided with the rest of the textbook...

    A test harness program for testing sorting methods is provided with the rest of the textbook program files. It is the file Sorts.java in the ch11 package. The program includes a swap method that is used by all the sorting methods to swap array elements. Describe an approach to modifying the program so that after calling a sorting method the program prints out the number of swaps needed by the sorting method. Implement your approach. Test your new program by...

  • This assignment is comprised of 3 parts: ​All files needed are located at the end of...

    This assignment is comprised of 3 parts: ​All files needed are located at the end of the directions. Part 1: Implementation of Dynamic Array, Stack, and Bag First, complete the Worksheets 14 (Dynamic Array), 15 (Dynamic Array Amortized Execution Time Analysis), 16 (Dynamic Array Stack), and 21 (Dynamic Array Bag). These worksheets will get you started on the implementations, but you will NOT turn them in. ​Do Not Worry about these, they are completed. Next, complete the dynamic array and...

  • And there was a buy-sell arrangement which laid out the conditions under which either shareholder could...

    And there was a buy-sell arrangement which laid out the conditions under which either shareholder could buy out the other. Paul knew that this offer would strengthen his financial picture…but did he really want a partner?It was going to be a long night. read the case study above and answer this question what would you do if you were Paul with regards to financing, and why? ntroductloh Paul McTaggart sat at his desk. Behind him, the computer screen flickered with...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT