Question
in c++ i have this lab to read from text file but i have errors in the header file and implementation file can you help
in c++ i have this lab to read from text file but i have errors in the header file and implementation file can you help me to fix it without change anything in the Lab2driver.cpp
Lab2driver.cpp
#include
#include
using namespace std;
#include "studentType.h"
//function prototype
void sort(studentType[], int);
const int SIZE = 5;
int main()
{
// creating an array of studentType's
studentType students[5];
//defining and opening the input file
ifstream data("lab2Data.txt");
// Read the data from the file
for (int pos = 0; pos < SIZE; pos++)
data >> students[pos];
// sort the array by LAST name (using the given sort function)
sort(students, SIZE);
// printing the array
for (int pos = 0; pos < SIZE; pos++)
{
students[pos].print(cout);
cout << endl;
}
return 0;
}
//function definition
void sort(studentType arr[], int s)
{
int index;
int smallestIndex;
int location;
studentType temp;
for (index = 0; index < s - 1; index++)
{
//Step a
smallestIndex = index;
for (location = index + 1; location < s; location++)
if (arr[location] < arr[smallestIndex])
smallestIndex = location;
//Step b
temp = arr[smallestIndex];
arr[smallestIndex] = arr[index];
arr[index] = temp;
}
}
studentType.h
#ifndef STUDENTTYPE_H #define STUDENTTYPE_H
#include
{ private: string firstName; string lastName; int credits; double gpa;
public: void getInfo(ifstream& in, studentType& s) {
getfName = firstName; getlName = lastName; getCridet = credits; getGpa = gpa; }
void print(ostream& out);
bool operator <(const studentType& s);
};
#endif
studentType.cpp (implementation file)
#include
void studentType:: getInfo(ifstream& in, studentType& s) { in >> s.firstName; in >> s.lastName; in >> s.credits; in >> s.gpa; }
void studentType::print(ostream& out) { out << endl << "First Name : " << studentType::firstName << endl; out << "Last Name : " << studentType::lastName << endl; out << "Credits : " << studentType::credits << endl; out << "GPA : " << studentType::gpa << endl; }
bool studentType::operator <(const studentType& s) { if (lastName < s.lastName) return true;
else return false; }
Lab2Data.txt
Paul McCartney 98 2.8 Eric Clapton 75 3.1 Joe Satriani 50 1.75 Ani DiFranco 105 2.95 Chuck Berry 24 0.25
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