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
  • 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! 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...

  • *****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...

  • 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...

  • 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...

  • yes you will need matlab software Can someone please help me. attached is the exercise i...

    yes you will need matlab software Can someone please help me. attached is the exercise i am doing in matlab. also attached is the exercise that i am suppose to be doing.also attached is part a of my code and part b. also attached is an error code i am getting. can someone please help me with this. thanks. explain in detail what i am doing wrong and what i need to do to fix it. you use enogn polnts...

  • 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...

  • I need help with this Java question. Please only answer in Java. Also, please answer it...

    I need help with this Java question. Please only answer in Java. Also, please answer it as simple as possible thanks. Create an application that reads a file that contains an email list, reformats the data, and writes the cleaned list to another file. Console File Cleaner Source file:  prospects.csv Cleaned file: prospects_clean.csv Congratulations! Your file has been cleaned! The prospect.csv file FIRST,LAST,EMAIL james,butler,jbutler@random.com Josephine,Darakjy,josephine_darakjy@darakjy.org ART,VENERE,ART@VENERE.ORG The prospect_clean.csv file First,Last,email James,Butler,jbutler@random.com Josephine,Darakjy,josephine_darakjy@darakjy.org Art,Venere,art@venere.org Specifications Your instructor should provide a CSV file...

  • Please help me to write a program in C++ with comments and to keep it simple...

    Please help me to write a program in C++ with comments and to keep it simple as possible. Also, post the output please. Thank you! Here is input data: 2333021 BOKOW, R. NS201 3 A 2333021 BOKOW, R. MG342 3 A 2333021 BOKOW, R. FA302 1 A 2574063 FALLIN, D. MK106 3 C 2574063 FALLIN, D. MA208 3 B 2574063 FALLIN, D. CM201 3 C 2574063 FALLIN, D. CP101 2 B 2663628 KINGSLEY, M. QA140 3 A 2663628 KINGSLEY, M....

  • Hello can someone please help me with the following assignment, I wanted to do this assignment...

    Hello can someone please help me with the following assignment, I wanted to do this assignment on the company Etsy, but I am lost on where to begin. Here is a link to their annual reports. https://investors.etsy.com/financials/annual-reports-and-proxy/default.aspx Students must select a public company that interests you. Obtain the company's most recent annual report or Form 10-K. The Form 10-K is a company's annually required filing with the Securities Exchange Commission (SEC). It includes the company's financial statements and accompanying notes....

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