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

1. Create a structure for acourse at your University which includes members for

ID: 3614208 • Letter: 1

Question

1.      Create a structure for acourse at your University which includes members for the classname, number, day and time of the class sessions, and a coursedescription (of up to 100 characters).

2.      Create an instance (variable)of this structure.

3.      Write the code to read fromthe user the course name and description and store it in thevariable from question #2. Make sure to handle the case where thecourse name has multiple words (eg., Introduction to ComputerScience II)

4.      Write a function prototypethat will take this course as an argument and returnthe  number of students in the course. (Just provide theprototype…do not attempt to implement the function)

5.      How would the above prototypechange if you wanted to pass an array of courses?

6.      Write a function that takesan array of courses as an argument and displays each coursename.

7.      Explain the differencebetween cin.get(), and cin.get(array, size)

8.      Explain the differencebetween cin.ignore(), cin.ignore(100,’ ’), andcin.ignore(100)

Explanation / Answer

1.      Create a structure for acourse at your University which includes members for the classname, number, day and time of the class sessions, and a coursedescription (of up to 100 characters).

2.      Create an instance (variable)of this structure.

3.      Write the code to read fromthe user the course name and description and store it in thevariable from question #2. Make sure to handle the case where thecourse name has multiple words (eg., Introduction to ComputerScience II)

4.      Write a function prototypethat will take this course as an argument and returnthe  number of students in the course. (Just provide theprototype…do not attempt to implement the function)



#include <iostream>
using namespace std;

struct Class {
string name;
string number;
string day;
string time;
char desc[100];
};

int numstudents(Class);

int main ()
{
Class cs;

cout << "Enter class name: ";
getline (cin,cs.name);
cout << "Enter number: ";
getline (cin,cs.number);
cout << "Enter meeting day: ";
getline (cin,cs.day);
cout << "Enter meeting time ";
getline (cin,cs.time);

system("pause");
return 0;
}


5.      How would the above prototypechange if you wanted to pass an array of courses?


         intnumstudents(Class[]);



6.      Write a function that takesan array of courses as an argument and displays each coursename.

#include <iostream>
using namespace std;

struct Class {
string name;
string number;
string day;
string time;
char desc[100];
};
cin.ignore(100,’ ’)
int print(Class[],int);

int main ()
{
Class cs[5];
for(int i=0;i<2;i++)
{
cout << "Enter class name: ";
getline (cin,cs[i].name);
cout << "Enter number: ";
getline (cin,cs[i].number);
cout << "Enter meeting day: ";
getline (cin,cs[i].day);
cout << "Enter meeting time ";
getline (cin,cs[i].time);
cout << "Enter class description ";
cin.get(cs[i].desc,100);
cout<<" ";
cin.ignore(100,' ');
}
print(cs,2);
system("pause");
return 0;
}

int print(Class cs[],int i)
{int j;
cout<<"Class Names ";
for(j=0;j<i;j++)
    cout<<cs[j].name<<endl;
}


7.      Explain the differencebetween cin.get()-get 1 element of type specified, andcin.get(array, size)-read size elements


8.      Explain the differencebetween cin.ignore()-ignore next character,

cin.ignore(100,’ ’)-ignore next 100 characters oruntil get a new line

, and cin.ignore(100)-ignore next 100 characters