Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help witing a C++ project that uses arrays, queues and templates for the

ID: 2246502 • Letter: I

Question

I need help witing a C++ project that uses arrays, queues and templates for the following program.

I need a header file (interface), .cpp (implementation) file and a .cpp usage file (main program).

I need to make an enrollment system for a University. Looking at Undergrad and Graduate students, I need to populate the array with new students from a txt file.

I then will enter who is a graduate and non-graduate student when I enter their info (name, id number, and grad or non-grad).

I need to implement a queue that will look at who is a graduate student and give them priority registration to enroll in a class.

I then need to remove the student from the queue and add them to a new txt file for students that are enrolled in the class.

So there is one txt file that I populate with students and another that I will create based on the queue.

Thanks in advance!  

Explanation / Answer

main.cpp

------------

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include "Student.h"
using namespace std;

int main()
{
ifstream myfile ("input.txt");
ofstream outputfile ("output.txt");
string line;
vector<string> v;
queue<Student> q;
queue<Student> q1;
if (myfile.is_open())
{
  
// Read the file content into a vector of strings
while ( getline (myfile,line) )
{
//cout << line << ' ';
v.push_back(line);
}
  
// Traverse the vector
vector<string>::iterator it;
int id;
bool grad;
for(it=v.begin() ; it<v.end(); it++ ) {
cin.clear();
string name = *it;
//cout<< name << endl; // prints name
Student s;
s.name=name;

  
cout<<"Please enter the id for student: " << name << endl;
cin>>id;

//cout<<id<<endl;
  
s.id=id;
  
cout<<"Please enter 1 for grad and 0 for undergrad for student: " << name << endl;
cin>>grad;
  

s.grad=grad;

// If the student is a grad push him to the grad queue otherwise push him to undergrad queue
if(grad){
q.push(s);
}
else{
q1.push(s);
}
}
myfile.close();

//merge grad and undergrad queues
while (!q1.empty())
{
Student s= q1.front();
q.push(s);
q1.pop();
}

// Traverse the merged queue and write the entries to an output file in order. The grad students will be given

// priority over undergrads while enrolling in the class. File output.txt will contain the prioritized entries

while (!q.empty())
{
Student s= q.front();
cout<<s.name<<","<<s.id<<","<<s.grad<<endl;

outputfile<<s.name<<","<<s.id<<","<<s.grad<<endl;
q.pop();
}

outputfile.close();
}

return 0;
}

// Student.h

# include <string>

class Student{

public:

std::string name;

int id;

bool grad;

};

input.txt:

Name1

Name2

Name3

Sample Output:

Please enter the id for student: Name1

101                                                                                                                                                                             

Please enter 1 for grad and 0 for undergrad for student: Name1   

1                                                                                                                                                                               

Please enter the id for student: Name2

102                                                                                                                                                                             

Please enter 1 for grad and 0 for undergrad for student: Name2   

0                                                                                                                                                                               

Please enter the id for student: Name3

103                                                                                                                                                                             

Please enter 1 for grad and 0 for undergrad for student: Name3   

1                                                                                                                                                                               

Name1,101,1

Name3,103,1

Name2,102,0

Please update input.txt with relevant student names prior to execution in your context.