C++ dynamic arrays to manage a set of students and their courses. File courses.t
ID: 3689992 • Letter: C
Question
C++ dynamic arrays to manage a set of students and their courses.
File courses.txt contains a list of student names, the number of courses taken, and the names of the courses. The first line of the file contains the number of students.
12
John Milligan
3 CIS100 CIS105 MAT113
Jill Kerning
5 CIS100 CIS105 MAT232 BIO100 ENG101
Aaron Spencer
4 CIS201 CIS225 MAT232 ENG101
Damon Hill
2 CIS334 CIS400
Kaitlyn Stamen
4 CIS100 CIS10 MAT113 BIO100
Debbie Martin
5 CIS100 CIS105 MAT232 CHY112 ENG101
Greg Nolan
2 CIS334 CIS450
Lynn Sanders
4 CIS334 CIS450 MAT250 BIO100
Alicia Thomas
4 CIS226 CIS450 MAT232 CHY112
Alan Turner
5 CIS100 CIS105 MAT232 BIO100 ENG101
Paul Henley
5 CIS100 CIS105 CIS334 ENG101 MAT232
Tim Copeland
1 CIS450
Create a dynamic array of structs of the size provided in the first line of the file. The struct definition should contain a C++ string name, an integer number of courses, and a C++ string pointer. Read the data into the dynamic array. Note that once the number of courses is read, the code can create the dynamic array of course names for the student.
Allow the user the following options.
a. Display all students and courses
b. Enter a student name and report a list of courses taken by the student
c. Enter a course number and report a list of all students taking this course.
Should come out like this:
Explanation / Answer
#include<iostream.h>
#include<constream.h>
class courses
{
public:
char s,c;
int i,n,ch;
srintg name[],course[];
void readdata()
{
cout<<"Enter no of studnts ";
cin>>n;
for(i=0;i<n;i++)
{
name= new sring;
cout<<"Enter name of student ">;
cin>>name;
}
for(i=0;i<n;i++)
course=new string;
cout<<"Enter course ";
cin>>course;
}
void disp()
{
for(i=0;i<n;i++)
{
cout<< "Name:"<< name;
}
for(i=0;i<n;i++)
{
cout<<"Course:"<<course;
}
}
void step()
{
cout<<"Enter your chioce";
cin>>ch;
switch(ch)
{
case1:
if(ch==s)
{
cout<<"Enter student name:";
cin>>name;
cout<<name << "is taking:"<< course;
}
case2:
if (ch==c)
{
cout<<"Enter course name";
cin>>course;
cout<<"Students taking" << course << "is:"<< name;
}
case 3:
if (ch==q)
{
cout<<"Quit";
}
default:
cout<<"Enter correct choice";
}
}
};
courses x;
{
x.readdata();
x.disp();
x.step();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.