write a c++ program in which it contains a list of 20 students with their names
ID: 3644473 • Letter: W
Question
write a c++ program in which it contains a list of 20 students with their names and ID, the program should allow the user to enter the student name and ID that enrolled for for the Computer Programming Class. The program should contain the class students and the list can't go over 20 students. The output should be the list of names and id of the students and the date and time that enrolled for the computer programming class.Posted below the classes that I have that I need to use for this program.
Date.cpp
#include<iostream>
#include<iomanip>
using namespace std;
#include"Date.h"
ostream &operator<<(ostream & output,const Date & tempDate)
{
output<<tempDate.month<<"/"<<tempDate.day<<"/"<<tempDate.year<<endl;
return output;
}//end function operator<<
istream &operator>>(istream &input,Date & tempDate)
{
input>>setw(2)>>tempDate.month;
input.ignore();//skip/
input>>setw(2)>>tempDate.day;
input.ignore();//skip/
input>>setw(4)>>tempDate.year;
return input;
}//end function operator>>
Date::Date(int tempMonth,int tempDay,int tempYear):month(tempMonth),day(tempDay),year(tempYear)
{
}//end constructor
Date::Date(const Date &tempDate):month(tempDate.month),
day(tempDate.day),year(tempDate.year)
{
}//end Date constructor
Date::~Date()
{
cout<<"Date object destructor"<<endl;
}//end ~Date
void Date::setValues(int tempMonth,int tempDay,int tempYear)
{
setMonth(tempMonth);
setDay(tempDay);
setYear(tempYear);
}//end set values
void Date::setMonth(int tempMonth)
{
this->checkMonth(tempMonth);
}//end setMonth
void Date::setDay(int tempDay)
{
this->day = checkDay(tempDay);
}//end setDay
void Date::setYear(int tempYear)
{
this->year=tempYear;
}//end setYear
int Date::getMonth()const
{
return this->month;
}//end getMonth
int Date::getDay()const
{
return this ->day;
}//end get day
int Date::getYear()const
{
return this->year;
}
int Date::checkMonth(int tempMonth)const //utlity function
{
if(tempMonth >=1 && tempMonth<= 12)
{
return (tempMonth);
}//end if
else{
cout<<"Invalid month("<<tempMonth<<")set to 1 ";
return 1;
}//end if
}//end checkMonth
int Date::checkDay(int tempDay) const //utilty function
{
static const int dayPerMonth[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
if(tempDay>0 && tempDay<=dayPerMonth[month])
{
return tempDay;
}//end if
if(month ==2 && tempDay==29 &&
(year %400 ==0||(year %4==0 && year %100 !=0)))
{
return tempDay;
}
cout<<"Invalid Day ("<<tempDay<<")set to 1 ";
return 1;
}//end checkDay
Date &Date::operator=(const Date & tempDate)
{
this->month = tempDate.getMonth();
this->day=tempDate.getDay();
this ->year=tempDate.getYear();
return *this;
}//end funcion operator=
Date.h
#ifndef Date_H
#define Date_H
class Date{
friend ostream &operator<<(ostream &,const Date &);
friend istream &operator>>(istream &,Date &);
private:
int month,day,year;
int checkDay(int)const;//utility function
int checkMonth(int)const;
public:
Date(int=11,int=17,int=2010);
Date(const Date &);
~Date();
void setValues(int,int,int);
void setMonth(int);
void setDay(int);
void setYear(int);
int getMonth()const;
int getDay()const;
int getYear()const;
Date &operator=(const Date &);
}; //end class date
#endif
student.cpp
#include<iostream>
#include<string>
using namespace std;
#include"student.h"
//#include "Phone.h"
ostream &operator<<(ostream &output, const student & tempStudent)
{
output<<"First Name:"<<tempStudent.firstName<<endl;
output<<"Last Name:"<<tempStudent.lastName<<endl;
output<<"Id:"<<tempStudent.id<<endl;
output<<"Phone:"<<tempStudent.birthDate<<endl;
output<<"Birthdate:"<<tempStudent.birthDate<<endl;
return output;
}//end function operator<<
istream &operator>>(istream &input, student &tempStudent)
{
cout<<"First Name:";
input>>tempStudent.firstName;
cout<<"Last Name:";
input>>tempStudent.lastName;
cout<<"ID: ";
input>>tempStudent.id;
cout<<"BirthDate mm/dd/yyyy:";
input>>tempStudent.birthDate;
cout<<"Phone ### ### ####";
input>>tempStudent.phone;
return input;
}//end function operator>>
student::student():firstName("Juan"),lastName("Del pueblo"),
id("12345"),birthDate(),phone()
{
}//end student
student::student(const MyString &tempFirstName, const MyString &tempLastName,
const MyString &tempID,const Date &tempBirthDate,const Phone &tempPhone)
:firstName(tempFirstName),lastName(tempLastName),id(tempID),birthDate(tempBirthDate),
phone(tempPhone)
{
}// end Student
student::student(const student &tempStudent):firstName(tempStudent.firstName),
lastName(tempStudent.lastName),id(tempStudent.id),birthDate(tempStudent.birthDate),
phone(tempStudent.phone)
{
}// end student
student::~student()
{
cout<<"Student object destructor"<<endl;
}//end student destructor
void student::setValues(const MyString &tempFirstName,const MyString &tempLastName,
const MyString &tempID,const Date &tempDate, const Phone &tempPhone)
{
setFirstName(tempFirstName);
setLastName(tempLastName);
setID(tempID);
setDate(tempDate);
setPhone(tempPhone);
}//end set values
void student::setID(const MyString &tempID)
{
id=tempID;
}// end setID
void student::setFirstName(const MyString &tempFirstName)
{
firstName = tempFirstName;
}// end setFirstName
void student::setLastName(const MyString &tempLastName)
{
lastName=tempLastName;
}//end setLastName
void student::setPhone(const Phone &tempPhone)
{
phone.setExchange(tempPhone.getExchange());
phone.setLine(tempPhone.getLine());
}//end setPhone;
void student::setDate(const Date &tempDate)
{
birthDate.setMonth(tempDate.getMonth());
birthDate.setDay(tempDate.getDay());
birthDate.setYear(tempDate.getYear());
}//end setDate
const MyString &student::getID()const
{
return this->id;
}//end getId
const MyString &student::getFirstName()const
{
return this->firstName;
}// end firstName
const MyString &student::getLastName()const
{
return this ->lastName;
}//end getLastName
const Phone& student::getPhone()const
{
return this->phone;
}//end getPhone
const Date& student::getDate()const
{
return this ->birthDate;
}//end getPhone
student &student::operator=(const student &tempStudent)
{
this ->firstName = tempStudent.getFirstName();
this ->lastName = tempStudent.getLastName();
this ->id = tempStudent.getID();
this ->phone = tempStudent.getPhone();
return *this;
}//end function operator=
student.h
#ifndef student_H
#define student_H
#include"Phone.h"
#include"Date.h"
#include"MyString.h"
class student{
friend ostream &operator<<(ostream &, const student &);
friend istream &operator<<(istream &, student &);
private:
MyString id;
MyString firstName;
MyString lastName;
Date birthDate;
Phone phone;
public:
student(const MyString &,const MyString &,const MyString &,
const Date &,const Phone &);
student(const student &);
student();
~student();
void setValues(const MyString &,const MyString&,const MyString&,const Date &,
const Phone &);
void setID(const MyString &);
void setFirstName(const MyString &);
void setLastName(const MyString &);
void setPhone(const Phone &);
void setDate(const Date &);
const MyString &getID()const;
const MyString &getFirstName()const;
const MyString &getLastName()const;
const Date& getDate() const;
const Phone& getPhone()const;
student &operator=(const student &);
friend ostream &operator<<(ostream&, const student &);
friend istream &operator>>(istream&, student &);
};// end class student
#endif
studentList.cpp
#include<iostream>
using namespace::std;
#include "studentList.h"
istream &operator>>(istream &input, studentList &tempStudentList){
int i,n;
student tempStudent;
cout<<"Entre el numero de estudiantes:";
input>>n;
for(i=0;i<n; i++){
input>>tempStudent;
while(tempStudentList.searchStudent(tempStudent) && ( tempStudentList.size !=0) ) {
cout<<"Entre de nuevo el estudiante #["<<i+1<<"]: ";
input>>tempStudent;
} //end while
tempStudentList.stdt[i] = tempStudent;
tempStudentList.size++;
tempStudentList.sortStudent();
}//end for
return input;
}//end function operator>>
ostream &operator<<(ostream &output, const studentList &tempStudentList){
int i;
for(i=0;i<tempStudentList.getSize(); i++) {
cout<<"Student["<<i+1<<"]: "<<endl;
output<<tempStudentList.stdt[i];
}//end for
cout<<endl;
return output;
}//end function operator <<
void studentList::sortStudent(){
student temp;
bool switched = true;
for(int pass=0;pass<(this->getSize()-1) && switched;pass++){
switched = false;
for(int j=0;j<(this->getSize()-pass-1);j++) {
if( (*this)[j].getID()>(*this)[j+1].getID()){
temp =stdt[j];
stdt[j] = stdt[j+1];
stdt[j+1]=temp;
switched = true;
}//end if
}//end for
}//end for
}//end sortStudent
studentList::studentList(){
size = 0;
}//end constructor
studentList::studentList(const studentList &tempStudentList):size(tempStudentList.size)
{
for(int i=0;i<getSize();i++){
*(stdt + i)= *(tempStudentList.stdt +i);
}//end for
}//end constructor
studentList::~studentList(){
}//end destructor
studentList &studentList::operator=(const studentList &tempStudentList){
int i;
size = tempStudentList.size;
for(i = 0; i<getSize();i++) {
stdt[i] = tempStudentList.stdt[i];
}//end for
return *this;
}//end function operator =
void studentList::operator+=(const student &tempStudent) {
if(!isFull() && !searchStudent(tempStudent)){
*(stdt +size) = tempStudent;
this->size++;
this->sortStudent();
} //end if
else{
cout<<"Array is full or repeatedly id "<<endl;
} //end else
}//end function operator +=
bool studentList::searchStudent(const MyString &tempId) const{
bool found = false;
MyString temp;
for(int i=0;i<this->getSize();i++){
temp= stdt[i].getID();
if( temp == tempId)
{
found = true;
i=size;
}//end if
}//end for
return found;
}//end function
bool studentList::searchStudent(const char *tempId) const{
bool found = false;
MyString temp;
for(int i=0;i<this->getSize();i++){
temp = stdt[i].getID();
cout<<temp<<" "<<tempId<<endl;
if( temp == tempId){
found = true;
i = size;
}//end if
}//end for
return found;
}//end function
bool studentList::searchStudent(const student &tempStudent) const{
bool found = false;
for(int i=0;i<this->getSize();i++){
if(stdt[i].getID() == tempStudent.getID()){
found = true;
i=size;
}//end if
}//end for
return found;
}//end function
int studentList::subscriptStudent(const MyString &tempId) const{
int subscript = -1;
MyString temp;
for(int i=0;i<this->getSize();i++){
temp = stdt[i].getID();
if(temp == tempId){
subscript = i;
i=size;
}//end if
}//end for
return subscript;
}//end function
int studentList::subscriptStudent(const char *tempId) const{
int subscript = -1;
MyString temp;
for(int i=0;i<this->getSize();i++){
temp = stdt[i].getID();
if(temp == tempId){
subscript = i;
i =size;
}//end if
}//end for
return subscript;
}//end function
int studentList::subscriptStudent(const student &tempStudent) const{
int subscript = -1;
for(int i=0;i<this->getSize();i++){
if(stdt[i].getID() == tempStudent.getID()){
subscript = i;
i=size;
}//end if
}//end for
return subscript;
}//end function
void studentList::operator-=(const MyString &tempId){
int subscript;
if(!isEmpty() && searchStudent(tempId)){
subscript = subscriptStudent(tempId);
for(int i=subscript;i<getSize()-1;i++){
*(stdt + i) = *(stdt +(i+1));
}//end for
size--;
}//ed if
else
{
cout<<"Invalid id"<<endl;
}//end else
}//end function operator -=
void studentList::operator-=(const char *tempId){
int subscript;
if(!isEmpty() && searchStudent(tempId)){
subscript = subscriptStudent(tempId);
for(int i=subscript;i<getSize()-1;i++){
*(stdt + i) = *(stdt +(i+1));
}//end for
size--;
}//end if
else{
cout<<"Invalid id"<<endl;
}//end else
}//end function operator -=
bool studentList::isEmpty() const{
return(this->size==0);
}//end function
bool studentList::isFull() const{
return(this->size==MAX_STD);
}//end function
int studentList::getSize() const{
return (this->size);
}//end function
student &studentList::operator[] (int subscript){
if((subscript < 0) || (subscript >= getSize())){
cout<<"Error: Subscript "<<subscript<<" out of range ";
exit(1);
}//end if
return stdt[subscript];
}//end function operator []
student studentList::operator[] (int subscript) const
{
if((subscript < 0) || (subscript >= getSize())) {
cout<<"Error: Subscript "<<subscript<<" out of range ";
exit(1);
}//end if
return stdt[subscript];
}//end function operator []
studentList.h
#ifndef STUDENTLIST_H
#define STUDENTLIST_H
#include"student.h"
const int MAX_STD = 10; //Cantidad maxima del arreglo
class studentList{
friend ostream &operator<<(ostream &, const studentList &);
friend istream &operator>>(istream &, studentList &);
private:
student stdt[MAX_STD];
int size;
void sortStudent();
public:
studentList();
studentList(const studentList &);
~studentList();
studentList &operator=(const studentList &);
void operator+=(const student&); //add student
bool searchStudent(const MyString &) const;
bool searchStudent(const char *) const;
bool searchStudent(const student &) const;
int subscriptStudent(const MyString &) const;
int subscriptStudent(const char *) const;
int subscriptStudent(const student &) const;
void operator-=(const MyString &);
void operator-=(const char *);
bool isEmpty() const;
bool isFull() const;
int getSize() const;
student&operator[] (int);
student operator[] (int) const;
};//end studentList class
#endif
MyString.h
#pragma once
const int MAX_LIST = 100;
class MyString
{
friend ostream &operator<<(ostream &, const MyString &);
friend istream &operator>>(istream &, MyString &);
friend bool operator==(const char *,const MyString &);
friend bool operator!=(const char *,const MyString &);
friend MyString operator+(const char *,const MyString &);
friend bool operator>(const char *,const MyString &);
friend bool operator<(const char *,const MyString &);
private:
int length;
char *sPtr;
void setMyString(const char *);
public:
MyString(const char * = "");
MyString(const MyString &);
~MyString();
MyString toUpperCase() const;
MyString toLowerCase() const;
const MyString &operator=(const MyString &);
const MyString &operator=(const char *);
const MyString &operator +=(const MyString &);
const MyString &operator +=(const char *);
MyString operator +(const MyString &);
MyString operator +(const char *);
bool operator !() const;
bool operator==(const MyString &) const;
bool operator==(const char *) const;
bool operator!=(const MyString &) const;
bool operator!=(const char *) const;
bool operator <(const MyString &) const;
bool operator <(const char *) const;
bool operator >(const MyString &) const;
bool operator >(const char *) const;
char &operator[](int);
char operator[](int) const;
MyString operator()(int, int=0) const;
int getLength() const;
}; // class MyString;
Explanation / Answer
#include #include #include struct student { char name[20]; int sem; int regno; float mark; }; struct student students[75]; void msort(int low,int high) // Recursive unction megrge sort { int i,j,h,mid,k; struct student temp[75]; if(lowmid) { while(jhigh) { while(hRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.