write a program that does the following: 1. Read a list with names and year born
ID: 3760703 • 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
6)
#include <iostream>
#include <ctime>
#include <string>
using namespace std;
int main ()
{
time_t now = time(0);
struct tm* today = localtime(&now);
string ampm="AM";
cout<<"Today:"<<endl;
cout<<"the year is "<<today->tm_year + 1900<<endl;
cout<<"the month is "<<today->tm_mon+1<<endl;
cout<< "the date is " << today->tm_mday<<endl;
int day=today->tm_wday;
switch(day)
{
case 0:cout<<"Sunday "; break;
case 1:cout<<"Monday "; break;
case 2:cout<<"Tuesday "; break;
case 3:cout<<"Wednesday "; break;
case 4:cout<<"Thursday "; break;
case 5:cout<<"Friday "; break;
case 6:cout<<"Saturday "; break;
}
cout<<today->tm_wday<<endl;
cout<<"Time:"<<endl;
int hour=today->tm_hour;
if(hour>12)
{
hour=hour-12;
ampm="PM";
}
cout<<hour;
cout<< ":" << today->tm_min;
cout<< ":" << today->tm_sec;
cout<<ampm<<endl;
system("pause");
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.