write a program that does the following: 1. Read a list with names and year born
ID: 644606 • Letter: W
Question
write a program that does the following:
1. Read a list with names and year born from a file into an array.
2. There will not be more than 30 names in the file.
3. Write a function that will sort the names with the correct year born. (A dual sort)
4. You must use a recursive quicksort (a quick sort).
5. After sorting, print out the alphabetical list with the age.
6* See the date-time program below for how to get the current year.
The quicksort works as follows. Call quicksort with the the arrays and min and max. If min=max the list has just one element and is thus sorted.
Otherwise use the first element from min to max as a pivot value. Partition the list (from min to max) so that all of the values less than or equal to the pivot value are before it and all of the values greater than or equal to the pivot value are after it. The pivot value is now in its proper place. Call quicksort to sort the list from min to pivot-1 and call quicksort to sort the list from pivot+1 to max
sample file
.
Explanation / Answer
When reading integers from file we have to check for file exist or not....then iterating each integer and compare each one...
same when reading integers from users...comparing each integer and find max
#include<iostream.h>
main(){
double number,max = INT_MIN
ifstream read;
read.open("numbers.txt");
if (read.fail())
{
cout<< "Input file opening failed. ";
exit(1);
}
while (read>>number)
{
if (number>max)
max=number;
}
cout<<"The maximum number is "<<max<<endl;
read.close();
}
-------------------------------------------------------------------------------------------------------------------------
#include <iostream>
using namespace std;
int main()
{
int n,max=0,number;
cout << "Enter how many numbers you want to Enter" << endl;
cin>>n;
for(int i=0;i<n;i++){
cout << "Enter number" << endl;
cin>>number;
if(max>number){
max=number;
}
}
cout<<"max number is"<<max;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.