Write a C program using arrays that will 1Read in data from
Write a C++ program using arrays that will;
1.Read in data from a data file of ten(10) records,
2.Print the original data,
3.Using the Bubble Sort algorithm, sort the data by year,
4.Print the sorted data,
5.Then, prompt the user to enter a year,
6. Use the Linear Search algorithm to find the record with that year
7. Then, display the found record, if record not found, print “Not Found”.
NOTE: Use functions for your output, sort and search routines.
here the data file
Name Year Tuition
Jason 2012 1222.33
Jackson 1992 900.23
Raymond 1993 2023.22
Korrey 1999 19920.22
Ellis 2000 700.23
Larry 2013 39.22
Micheal 2014 100.23
Isiah 2011 102.44
please help! with screenshot
Solution
// C++ code sort data and find a record
#include <cstdlib>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <fstream>
using namespace std;
int main()
{
string name[10];
int year[10];
double tution[10];
int index = 0;
ifstream fin(\"inputfile.txt\");
while(true)
{
fin >> name[index];
fin >> year[index];
fin >> tution[index];
index++;
if(fin.eof())
break;
}
cout << \"Original Data\ \";
cout << \"Name\\tYear\\tTution\ \";
cout << \"----------------------\ \";
for (int i = 0; i < 10; ++i)
{
cout << name[i] << \"\\t\" << year[i] << \"\\t\" << tution[i] << \"\ \";
}
cout << endl;
// bubble sort
for (int i = 0; i < 10; ++i)
{
for (int j = 0; j < 10; ++j)
{
if(year[i] < year[j])
{
swap(year[i],year[j]);
swap(name[i],name[j]);
swap(tution[i],tution[j]);
}
}
}
cout << \"Sorted Data\ \";
cout << \"Name\\tYear\\tTution\ \";
cout << \"----------------------\ \";
for (int i = 0; i < 10; ++i)
{
cout << name[i] << \"\\t\" << year[i] << \"\\t\" << tution[i] << \"\ \";
}
int yr;
cout << \"\ Enter year: \";
cin >> yr;
for (int i = 0; i < 10; ++i)
{
if (year[i] == yr)
{
cout << \"Record found: \" << name[i] << \"\\t\" << year[i] << \"\\t\" << tution[i] << endl;
return 0;
}
}
cout << \"Record not found\ \";
return 0;
}
/*
output:
Original Data
Name Year Tution
----------------------
Ben 1992 0
David 2011 1582.38
jamie 2012 728.82
ayush 2013 567.4
akash 2001 345.2
james 2000 567.4
jason 1996 568
chris 2016 569.3
alex 2020 458.1
kathy 2006 1000.56
Sorted Data
Name Year Tution
----------------------
Ben 1992 0
jason 1996 568
james 2000 567.4
akash 2001 345.2
kathy 2006 1000.56
David 2011 1582.38
jamie 2012 728.82
ayush 2013 567.4
chris 2016 569.3
alex 2020 458.1
Enter year: 2011
Record found: David 2011 1582.38
*/


