This programming assigment has me some what consfused. From what I\'m to underst
ID: 642003 • Letter: T
Question
This programming assigment has me some what consfused. From what I'm to understand I'm supposed to input my data into an array from a text file print it then bubble sort that and allow the user to do a search using a year but I'm unclear on how to go about it.
Program 5
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
Explanation / Answer
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main ()
{
string line;
ifstream myfile ("bubblesort.txt");
if (myfile.is_open())
{
while ( myfile.good() )
{
getline (myfile,line);
cout << line << endl;
}
myfile.close();
}
else cout << "Unable to open file";
return 0;
}
have a class
class Student
{
string name;
unsigned int year;
unsigned float tuition;
}
As you read each line, allocate new object and populate the object from each line. Once you have all objects allocated, you can then sort based on year field in each object.
And de-allocate objects before exiting the program.
Hope this helps.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.