Programming Homework Help

CS 101 CUNY Queensborough Class Roster Program Question

 

Goal

We want to make a Class Roster program which saves the today’s attendance records of CS101 students. To allow a dynamic roster, we will use vector types for names of students and their attendance records.

For the names of students, we use names variable of vector<string> type. vector<string> names;

To record the today’s attendance records, we use attedances of vector<char> type. vector<char> attendances;

page1image14071488

Here we use the character P as the presence, L as the lateness, A as the absence, and E as the excuse.

Note: names and attendances are related by the index. For example, if

  names[3]="Henry";
  atttendances[3]='L';

So the name “Henry” and attendance ‘L’ are relate by the index 3. Of course, the index started with 0. Therefore the sizes of names and attendances should be exactly same.

Question
In this project, we will make

  void add(vector<string>& names, vector<char>& attendances);
  int count(const vector<char>& attendances, char att);
  void report(const vector<char>& attendances);
  void clear(vector<string>& names, vector<char>& attendances);

With this main function,

  #include<iostream>
  #include<string>
  #include<vector>
  using namespace std;
  void add(vector<string>& names, vector<char>& attendances);
  int count(const vector<char>& attendances, char att);
  void report(const vector<char>& attendances);
  void clear(vector<string>& names, vector<char>& attendances);
  int main(){
      vector<string> names;
      vector<char> attendances;
      string choice="";
      do{

cout<<“Attendance Roster”<<endl; cout<<“a. Add new students.”<<endl; cout<<“b. Report the attendance.”<<endl; cout<<“c. Clear the roster.”<<endl; cout<<“d. Stop.”<<endl;
cout<<“Choose one of choices(a,b,c,d):”; cin>>choice;
if(choice==”a”) add(names, attendances); else if(choice==”b”) report(attendances);

else if(choice==”c”) clear(names, attendances); }while(choice != “d”);
cout<<“Bye.”<<endl;

}

we may have the following screenshot.

Attendance Roster
a. Add new students.
b. Report the attendance.
c. Clear the roster.
d. Stop.
Choose one of choices(a,b,c,d):a
Type the name of student:James
Type the record of attendances(A,L,E,P):L Do you want to add more students?(y/n):y Type the name of student:Harden
Type the record of attendances(A,L,E,P):E Do you want to add more students?(y/n):n Attendance Roster
a. Add new students.
b. Report the attendance.
c. Clear the roster.
d. Stop.
Choose one of choices(a,b,c,d):b
The number of absent students is 0.
The number of late students is 1.
The number of excused students is 1.
The number of present students is 0. Attendance Roster
a. Add new students.
b. Report the attendance.
c. Clear the roster.
d. Stop.
Choose one of choices(a,b,c,d):a
Type the name of student:Curry
Type the record of attendances(A,L,E,P):E Do you want to add more students?(y/n):y Type the name of student:Thompson
Type the record of attendances(A,L,E,P):P Do you want to add more students?(y/n):n Attendance Roster
a. Add new students.
b. Report the attendance.
c. Clear the roster.
d. Stop.
Choose one of choices(a,b,c,d):b
The number of absent students is 0.
The number of late students is 1.
The number of excused students is 2.

The number of present students is 1. Attendance Roster
a. Add new students.
b. Report the attendance.

c. Clear the roster.
d. Stop.
Choose one of choices(a,b,c,d):c All of records were cleared. Attendance Roster
a. Add new students.
b. Report the attendance.
c. Clear the roster.
d. Stop.
Choose one of choices(a,b,c,d):b There is no student.
Attendance Roster
a. Add new students.
b. Report the attendance.
c. Clear the roster.
d. Stop.
Choose one of choices(a,b,c,d):d Bye.

add

Make a void add(vector<string>& names, vector<char>& attendances) which adds new names and attendance records of students. For a simpilicity, we only type the last name without any space.

So we can still use cin.
We assume that a user types A, L, E and P properly. Please, check the following screenshot.

  Type the name of student:James
  Type the record of attendances(A,L,E,P):L
  Do you want to add more students?(y/n):y
  Type the name of student:Curry
  Type the record of attendances(A,L,E,P):E
  Do you want to add more students?(y/n):n

count
Make a int count(const vector<char>& attendances, char att) which returns the

number of attendance records for att. att will be one of A,L,E,P where

  A: absent
  L: late
  E: excused
  P: Present

For example,

cout<<count(attendances,’L’); will print the number of late students.

  cout<<count(attendances,'A');

will print the number of absent students. report

Make void report(const vector<char>& attendances) which returns the report uing above count function. For example, if

  vector<string> names={"Bob","Jane","Jim","Lee","Python","Java"};
  vector<char> attendances={'P','A','A','E','A','E'};

, the following code

  report(attendances);

will print the these results.

The number of absent students is 2. The number of late students is 0. The number of excused students is 2. The number of present students is 1.

If names and attendances are empty like vector<string> names;

vector<char> attendances; , the following code

report(attendances);

will print the this result.

There is no student. clear

Make a void clear(vector<string>& names, vector<char>& attendances) which makes names and attendances empty. To make them empty, you may use clear()

member function of the vector class. vector<int> v {1,2};// v={1,2}

v.clear(); // now v={} empty and size=0
Ref of clear(): http://www.cplusplus.com/reference/vector/vector/c…

For example, if we run the code below,

  clear(names,attendances);

, it will show

All of records were cleared.

Then the following code

  report(attendances);

will print the this result since they are empty.

There is no student.