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

Make sure the loop is there and that it stops and gives out the report after the

ID: 3579301 • Letter: M

Question

Make sure the loop is there and that it stops and gives out the report after the user inputs zeros in the ID.

Basic Obj oriented format!

ITP 120 Program 3 You are to prompt the user for a 3-digit ID and a birth date for each college student. For the birth date, prompt for 3 integers in the order month, day, and year. Be sure to validate the birth date (for the year, it must be in the 1900's. Don't worry about validating if it's a leap year). The last student ID will be 000. You are to output the ID and birth date for each student. The birth date should be output in the format February 15, 1982. Also, output how many students were processed, how many of the students had a February 29th birth date, and the birth date of the oldest student. Be sure to use good programming style. Object-oriented programming techniques are to be used. You are to submit a secure folder containing the following: 1. A hard copy of your class description and pseudocode 2. A hard copy of your source code. 3. Your flash drive which contains your source code. Be sure your name is on the outside of your flash drive 4. Your executable class and file are to be named studentBirthdate. The folder is to be named Program 3.

Explanation / Answer

#include<iostream>
using namespace std;
//Class Student defined
class student
{
//Data member
int id;
int month;
int year;
int date;
public:
//Default Constructor to initialize data member
student()
{
id = 0;
month = 0;
year = 0;
date = 0;
}
//Accept student BOB
void acc();
//Display student DOB
void disp();
//Count number of students match the specified DOB
int countMath(student [], int);
//Displays oldest student information
void oldestStudent(student [], int);
};
//Accept method defined
void student::acc()
{
int no, ori, co;
//Validates till 3 digit student id is entered
do
{
//Counter for the digit
co = 0;
//Accept the ID
cout<<" Enter the Student ID: ";
cin>>no;
ori = no;
//Loops till no becomes zero
while(no!= 0)
{
//Find out the quotient and store it in no
no /= 10;
//Increases the counter by 1
co++;
}
//if counter is 3 then valid ID
if(co == 3)
{
//Store the valid ID in the class data member
id = ori;
break;
}
//Otherwise show error and asks to reenter the id
else
{
cout<<"ERROR: Invalid Id. Please reenter: ";
}
}while(1);
//Validates date
do
{
//Accepts date
cout<<" Enter the DOB date: ";
cin>>no;
//If the date lies between 1 and 31 it is valid date
if(no > 0 && no < 32)
{
//Store the valid date in the class data member
date = no;
break;
}
//Otherwise show error and asks to reenter the date
else
{
cout<<"ERROR: Invalid Date. Please reenter: ";
}
}while(1);
//Validates month
do
{
//Accepts month
cout<<" Enter the DOB Month: ";
cin>>no;
//If the month lies between 1 and 12 it is valid month
if(no > 0 && no < 13)
{
//Store the valid month in the class data member
month = no;
break;
}
//Otherwise show error and asks to reenter the month
else
{
cout<<"ERROR: Invalid Month. Please reenter: ";
}
}while(1);
//Validates year
do
{
//Initializes the counter to 0
co = 0;
//Accept year
cout<<" Enter DOB Year: ";
cin>>no;
//Keep a duplicate copy of the year
ori = no;
//Loop till no is not equal to 0
while(no != 0)
{
//Find out he quotient and store it in no
no /= 10;
//Increase the counter
co++;
}
//If the counter is 4 then valid year
if(co == 4)
{
year = ori;
break;
}
//Otherwise show error and asks to reenter the year
else
{
cout<<"ERROR: Invalid Year. Please reenter: ";
}
}while(1);
}
//Display the student information as per the format
void student::disp()
{
cout<<" ID: "<<id;
//Display the month in character format
switch(month)
{
case 1: cout<<" January "; break;
case 2: cout<<" February "; break;
case 3: cout<<" March "; break;
case 4: cout<<" April "; break;
case 5: cout<<" May "; break;
case 6: cout<<" June "; break;
case 7: cout<<" July "; break;
case 8: cout<<" August "; break;
case 9: cout<<" September "; break;
case 10: cout<<" October "; break;
case 11: cout<<" November "; break;
case 12: cout<<" December "; break;
}
cout<<date<<", "<<year;
}
//Count and returns number of students having specified date of birth
int student::countMath(student *st, int no)
{
//Initializes the counter to 0
int co = 0;
//Loops till end of the student record
for(int c = 0; c < no; c++)
{
//Finds the match date of birth 29th February
if(st[c].month == 2 && st[c].date == 29)
//If match found increase the counter by 1
co++;
}
//Return the counter
return co;
}
//Find out the oldest student in the student record
void student::oldestStudent(student *st, int no)
{
//Assume the first student is the oldest one
int mini = st[0].year;
//Set the position to 0
int po = 0;
//Loop till end of the student record
for(int c = 1; c < no; c++)
{
//Compare next student year with the existing minimum
if(st[c].year < mini)
{
//If it is less. update the minimum with the existing student year
mini = st[c].year;
//Reset the position
po = c;
}
}
//Display the oldest student information
cout<<" Oldest Student ID: "<<st[po].id<<" Month: "<<st[po].month<<" Year: "<<st[po].year;
}
int main()
{
//Creates a student object of size 50
student s[50];
int c = 0;
char ch;
//Loops till user choice
do
{
//Accept student information
s[c].acc();
//Increase the student counter by 1
c++;
//Asks the user choice
cout<<" Would you like to enter more: (y / n)";
cin>>ch;
//If no stop
if(ch == 'N' || ch == 'n')
break;
//If yes continue
if(ch == 'Y' || ch == 'y')
continue;
//Otherwise show an error message and stop
else
{
cout<<"ERROR: Invalid entry! ";
break;
}
}while(1);
cout<<" Displaying Student DOB ";
for(int d = 0; d < c; d++)
s[d].disp();
cout<<" Number of students processed: "<<c;
cout<<" "<<s[0].countMath(s, c)<<" number of students having birth day on February 29";
s[0].oldestStudent(s, c);
}

Output:

Enter the Student ID: 111

Enter the DOB date: 29

Enter the DOB Month: 2

Enter DOB Year: 1989

Would you like to enter more: (y / n)y

Enter the Student ID: 23
ERROR: Invalid Id. Please reenter:
Enter the Student ID: 222

Enter the DOB date: 12

Enter the DOB Month: 6

Enter DOB Year: 2000

Would you like to enter more: (y / n)y

Enter the Student ID: 333

Enter the DOB date: 29

Enter the DOB Month: 2

Enter DOB Year: 1980

Would you like to enter more: (y / n)y

Enter the Student ID: 444

Enter the DOB date: 12

Enter the DOB Month: 12

Enter DOB Year: 2012

Would you like to enter more: (y / n)y

Enter the Student ID: 123

Enter the DOB date: 32
ERROR: Invalid Date. Please reenter:
Enter the DOB date: 29

Enter the DOB Month: 14
ERROR: Invalid Month. Please reenter:
Enter the DOB Month: 10

Enter DOB Year: 2001

Would you like to enter more: (y / n)n

Displaying Student DOB

ID: 111 February 29, 1989
ID: 222 June 12, 2000
ID: 333 February 29, 1980
ID: 444 December 12, 2012
ID: 123 October 29, 2001
Number of students processed: 5
2 number of students having birth day on February 29
Oldest Student ID: 333
Month: 2
Year: 1980

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote