Question
Write a C++ program using arrays that will; Read in data from a data file of ten(10) records, Print the original data, Using the Bubble
Write a C++ program using arrays that will;
Read in data from a data file of ten(10) records,
Print the original data,
Using the Bubble Sort algorithm, sort the data by year
Print the sorted data,
Then, prompt the user to enter a year,
Use the Linear Search algorithm to find the record with that year
Then, display the found record, if record not found, print Not Found.
NOTE: Use functions for your output, sort and search routines.
Original Data
Name Year Tuition
Aaron 2011 1582.38
Michael 2012 728.82
Joseph 1992 0
: : : : : : : : :
Sorted Data
Name Year Tuition
Joseph 1992 0.00
Michael 2011 1582.38
Aaron 2012 728.82
: : : : : : : : :
Enter year: 2011
Record found.
Aaron 2011 1582.38
___________________________________
This is what I have
#include
using namespace std; typedef struct Student { string name; int year; double fee; }Student; void bubbleSort(Student Array[], int n) { for (int i = 0; i < n - 1; i++) for (int j = 0; j < n - i - 1; j++) if (Array[j].year > Array[j + 1].year) { Student temp = Array[j]; Array[j] = Array[j + 1]; Array[j + 1] = temp; } } int main() { ifstream fin; fin.open("TuitionFee.txt"); Student Array[10]; int count = 0; for (int i = 0; i < 10; i++) { if (fin.eof()) break; fin >> Array[i].name; fin >> Array[i].year; fin >> Array[i].fee; count++; } for (int i = 0; i < count; i++) cout << Array[i].name << " " << Array[i].year << " " << Array[i].fee << endl; cout << endl << endl; bubbleSort(Array, count); for (int i = 0; i < count; i++) cout << Array[i].name << " " << Array[i].year << " " << Array[i].fee << endl; }
_____________________________________________________________
all of it is correct! My teacher said I need this part sorted in a get function
int main() { ifstream fin; fin.open("TuitionFee.txt"); Student Array[10]; int count = 0; for (int i = 0; i < 10; i++) { if (fin.eof()) break; fin >> Array[i].name; fin >> Array[i].year; fin >> Array[i].fee; count++; } for (int i = 0; i < count; i++) cout << Array[i].name << " " << Array[i].year << " " << Array[i].fee << endl; cout << endl << endl; bubbleSort(Array, count); for (int i = 0; i < count; i++) cout << Array[i].name << " " << Array[i].year << " " << Array[i].fee << endl; }
__________________________________________________________
FYI I did this in Visual Studios in C++
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started