Question

Can someone help please. I had help but it's not working. PLEASE DO BOTH PARTS! Please...

Can someone help please. I had help but it's not working. PLEASE DO BOTH PARTS! Please make sure to read the entire problem and do both parts 
PLEASE DO NOT write it out I have a hard time reading people's hand writing please just type it out. Thanks for any and all help I appreciate it!

Here is the problem:

Part A: Write a c++ program that prompts the user to enter information about course enrollments, and writes this data to file coursedata.txt, located in the folder Test on drive C:. Use CSIT courses currently being offered, but include only those taught by one of the following professors: Buzi, Hu, Maloney, Scialdone, Zubairi. For each course, enter the subject code and number, the instructor's last name, and the enrollment - for example:

CSIT 201
Zubairi
30

CSIT 221
Buzi
16

CSIT 241
Maloney
24

...

CSIT 463
Buzi
22

Note that the data should be written to the file in increasing order by course number.

Part B: Write a program that reads the data from the file produced in Part A, and produces a report showing the courses taught by each instructor, along with their enrollments, and the total enrollment for that instructor. This report should be written to the file coursereport.txt, located in the folder Test on drive C:. It should be in order by instructor last name - for example:

Buzi
CSIT 221 16
CSIT 341 25
CSIT 463 22
Total: 63

...

Zubairi
CSIT 201 30
CSIT 251 23
CSIT 425 15
Total: 68

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<fstream>
#include<iostream>
using namespace std;

#include <iostream>
using namespace std;
//Class Defined for course
class Course
{
private:
//data members of class
int courseNo;
string courseName;
string instructorName;
int numberofStu;
public:
//To accept data
void getdata()
{
cout<<"\n Enter Subject Name: ";
cin>>courseName;
cout<<"\n Enter Subject Code: ";
cin>>courseNo;
cout<<"\n Enter Instructor Name: ";
cin>>instructorName;
cout<<"\n Enter Number of students: ";
cin>>numberofStu;
}//End of function
//To display data
void display()
{
cout<<"\n Subject Name: "<<courseName;
cout<<"\n Subject Code: "<<courseNo;
cout<<"\n Instructor Name: "<<instructorName;
cout<<"\n Number of students: "<<numberofStu;
}//End of function
//To write data to file
void write(int no, Course co[])
{
fstream f;
//Open file in write mode
f.open("coursedata.txt",ios::in|ios::out|ios::binary);
//If file does not exit show error
if(!f)
{
cerr<<"Cannot open file !";
return;
}//End of if
//Loops till number of students entered by the user
for(int x = 0; x < no; x++)
//Write data to file
f.write((char*)&co[x],sizeof(co[x]));
//close file
f.close();
}//end of function
//Read data from file
void read(int no, Course co[])
{
fstream f;
//Open file in read mode
f.open("coursedata.txt",ios::in|ios::out|ios::binary);
f.seekg(0); //The question is about this statement;
//Loops till number of students entered by the user
for(int j=0;j<no;j++)
{
//Read data from file and store in class object
f.read((char*)&co[j],sizeof(co[j]));
}//End of loop
//Close file
f.close();
}//End of function
//Sort the file according to course number
void SortNo(int no, Course co[])
{
int Temp, x, y;
//Loops till number of students entered by the user
for(x = 0; x < no; x++)
{
for(y = 0; y < no - x - 1; y++)
{
//Compares and swap
if(co[y].courseNo > co[y + 1].courseNo)
{
Temp = co[y].courseNo;
co[y].courseNo = co[y + 1].courseNo;
co[y + 1].courseNo = Temp;
}//End of if
}//End of inner for loop
}//End of outer for loop
}//end of function
//Sort data according to instructor name
void SortString(int no, Course co[])
{
int x, y;
Course Temp;
//Loops till number of students entered by the user
for(x = 0; x < no; x++)
{
for(y = 0; y < no - x - 1; y++)
{
//Compares and swap
if(co[x].instructorName.compare(co[y].instructorName) <= 0)
{
Temp = co[y];
co[y] = co[y + 1];
co[y + 1] = Temp;
}//End of if
}//End of inner loop
}//End of outer loop
}//End of function
//Counts the total according to instructor name
void countTotal(int no, Course co[])
{
int tot, x, y;
//Loops till number of students entered by the user
for(x = 0; x < no; x++)
{
tot = 0; //y = x + 1;
cout<<"\n Instructor Name: "<<co[x].instructorName;
for(y = x; y < no; y++)
{
//Checks if instructor name is same
if(co[x].instructorName.compare(co[y].instructorName) == 0)
{
cout<<endl<<co[y].courseName<<" "<<co[y].courseNo<<" "<<co[y].numberofStu;
//counts total of students
tot += co[y].numberofStu;
}//End of if
else
break;
}//End of inner loop
cout<<"\nTotal: "<<tot;
x = y;
}//End of outer loop
}//End of function
};//End of class
//Main function
int main()
{
int no;
//Accepts number of students
cout<<"\n Enter number of course you want? ";
cin>>no;
Course co[50];
cout<<"\n Enter "<<no<<" course details \n";
//Loops till number of students entered by the user
for(int i=0;i<no;i++)
{
//Accepts data for class objects
co[i].getdata();
}//End of loop
//Sort the object according to course number
co[0].SortNo(no, co);
//Writes data to file
co[0].write(no, co);
//Reads data from file
co[0].read(no, co);
//Sorts data according to instructor name
co[0].SortString(no, co);
//Loops till number of students entered by the user
for(int i=0;i<no;i++)
{
//Displays course information
co[i].display();
}//End of loop
//Counts total number of students according to instructor name
co[0].countTotal(no, co);
}//End of main

Output:

Enter number of course you want? 5

Enter 5 course details

Enter Subject Name: cc

Enter Subject Code: 12

Enter Instructor Name: Pyari

Enter Number of students: 10

Enter Subject Name: cc

Enter Subject Code: 23

Enter Instructor Name: Ramesh

Enter Number of students: 5

Enter Subject Name: cc

Enter Subject Code: 11

Enter Instructor Name: Pyari

Enter Number of students: 10

Enter Subject Name: cc

Enter Subject Code: 22

Enter Instructor Name: Ramesh

Enter Number of students: 5

Enter Subject Name: cc

Enter Subject Code: 10

Enter Instructor Name: Pyari

Enter Number of students: 10

Subject Name: cc
Subject Code: 12
Instructor Name: Pyari
Number of students: 10
Subject Name: cc
Subject Code: 23
Instructor Name: Pyari
Number of students: 10
Subject Name: cc
Subject Code: 10
Instructor Name: Pyari
Number of students: 10
Subject Name: cc
Subject Code: 11
Instructor Name: Ramesh
Number of students: 5
Subject Name: cc
Subject Code: 22
Instructor Name: Ramesh
Number of students: 5
Instructor Name: Pyari
cc 12 10
cc 23 10
cc 10 10
Total: 30
Instructor Name: Ramesh
cc 11 5
cc 22 5
Total: 10

Add a comment
Know the answer?
Add Answer to:
Can someone help please. I had help but it's not working. PLEASE DO BOTH PARTS! Please...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using Python. Please help! The output should looks like below. Please follow the emphasis. I think...

    Using Python. Please help! The output should looks like below. Please follow the emphasis. I think it just prompt user to input course name. Write a modular program that creates a dictionary containing course numbers and the room numbers of the rooms where the courses meet. The dictionary should have the following key- value pairs: Course Number (key) Room Number (value) CS101 3004 CS102 4501 CS103 6755 NT110 1244 CM241 1411 The program should also create a dictionary containing course...

  • Hi! I need help answering these 3 questions on SQLQuery. Please help! The database is below....

    Hi! I need help answering these 3 questions on SQLQuery. Please help! The database is below. 1. Count the number of courses taught by all adjunct and full time faculty members during the semester and their total enrollments for all classes they teach. 2. List first and last names only of all adjunct faculty members who are teaching more than 1 course , the total enrollment for those courses, and the number of courses the faculty members teach. 3. Display...

  • In JAVA please! Write program for exercises You will write a Graphical User Interface(GUI) application to manage student...

    In JAVA please! Write program for exercises You will write a Graphical User Interface(GUI) application to manage student information system. The application should allow: 1. Collect student information and store it in a binary data file. Each student is identified by an unique ID. The user should be able to view/edit an existing student. Do not allow student to edit ID. 2. Collect Course information and store it in a separate data file. Each course is identified by an unique...

  • *****Can someone please HELP me with this assignment please, I am struggling with this assignment and...

    *****Can someone please HELP me with this assignment please, I am struggling with this assignment and would appreciate some help, needs to be done in c/c++ ******* (100 marks) In this problem, you will write a file transfer program for transferring files between two computers connected by a network. The protocol that you will implement is called the Simple File Transfer Protocol (SFTP). The complete description for SFTP is given below. PART 1 SFTP is a simple protocol for transferring...

  • SAS programming . Can someone help me on report 2 it’s not working and I do...

    SAS programming . Can someone help me on report 2 it’s not working and I do not know if I’m doing it right. 12.14.4.4. 2.1.2. 3.4.2 3 2 5 2 5 1 5 1 3 5 5 2 5 4 1 1 5.5 3.5.5.3.5-53-3-1, 1,3-3.12 334 3423 53533.22125253142 1 545 322142433 13451551 54514 5.4.1 4.3.3.1 5.22 201 201 009 210 201 202 013 004 005 006 997 300 009 400 400 004 ons dos 100 102 103 104 105 006...

  • hi, please help in c++. I dont understand how to do this, and a lot of...

    hi, please help in c++. I dont understand how to do this, and a lot of the ways on the internet is confusing me, i am a beginner. with all steps and explantions, will rate! Write a program that determines the frequency of each char in an input file. Your program should . read in an unknown number of chars from an input file named input.txt, • using a function written by you, determine the frequency of occurrence of each...

  • having trouble understanding what to do. can someone help please I have Excel it's not working...

    having trouble understanding what to do. can someone help please I have Excel it's not working gi HW,2 and Recitaiton 2 × Φ Chapter 2 Filled.pdf 2%20and% //sakai.uri.edu/access/content/group/702e45af-c2f8-43ca-a53c-9137c003efa/H Use Excer to answer this questro credit. Exercise 2.90 (data posted on SAKAI) on page 70 in the textbook (posted on Sakai). Answer the following questions: a. b. c. d. Determine a frequency distribution Obtain a relative frequency distribution Plot a frequency histogram based on your results from part (a) Plot a...

  • use  JOptionPane to display output Can someone please help write a program in Java using loops, not...

    use  JOptionPane to display output Can someone please help write a program in Java using loops, not HashMap Test 1 Grades After the class complete the first exam, I saved all of the grades in a text file called test1.txt. Your job is to do some analysis on the grades for me. Input: There will not be any input for this program. This is called a batch program because there will be no user interaction other than to run the program....

  • Can someone plz help me??? I would like a website that has to do with guitars...

    Can someone plz help me??? I would like a website that has to do with guitars or something to do with music, someone asked me what kind of website I would like to have and that would be awesome. The attributes to be included, are below. I need a small website that to where I need to interlink a CSS file into the HTML file. I don't know to save the files to have to be able to run with...

  • can you please follow all the instructions ? The answers that I got has either missing...

    can you please follow all the instructions ? The answers that I got has either missing range for loop or one funtion . Read the instructions carefully. At least 10% will be deducted if the instructions are not followed. For general lab requirements, see General Lab Requirements. Do not prompt the user for input during the execution of your program. Do not pause at the end of the execution waiting for the user's input. Notes 1. Your program should use...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT