Question

Use C++ to create a class called Student, which represents the students of a university. A student is defined with the following attributes: id number (int), first name (string), last name (string), date of birth (string), address (string). and telephone (area code (int) and 7-digit telephone number(string). The member functions of the class Student must perform the following operations: Return the id numb Return the first name of the student Modify the first name of the student. . Return the last name of the student Modify the last name of the student . Return the full name, i.e., first name and last name.. . Return the date of birth. . . Modify the date of birth. . Return the age of the student.. Return the address of the student. . Return the telephone number.. . Return true if two given students have the same last name. Return false otherwise. . Modify the address of the student.. Modify the telephone number. . . Return true if two given students are roommates, i.e., they live in the same address Test your class by prompting the user to enter information about two particular students Create two objects of the class Student with the information entered by the user, and finally, and test the member functions of the class.. Deliverables:. A file called student.h that contains the specification of the class.- . A file called student.cpp that contains the implementation of the member functions of the class. A file called teststudent.cpp that contains the main function..
0 0
Add a comment Improve this question Transcribed image text
Answer #1

C++ code:

student.h:

#ifndef STUDENT_H
#define STUDENT_H

#include <string>
using namespace std;

class Student
{
private:
int ID;
string first_name;
string last_name;
string date_of_birth;
int area_code;
string telephone_number;
string address;
public:
Student();
void setStudent(int ID, string first_name, string last_name, string date_of_birth, string address, int code, string phn);
int getID();
void setID(int id);
  
string getFirstName();
void setFirstName(string fn);
  
string getLastName();
void setLastName(string sn);
  
string getDOB();
void setDOB(string dob);
  
string getFullName();
  
string getAddress();
void setAddress(string addr);
  
string getTelephoneNumber();
void setTelephoneNumber(int code, string ph);
  
bool sameLastName(Student s2);
bool sameAddress(Student s1);
};
#endif

student.cpp:

#include "student.h"
#include <iostream>
#include <string>
using namespace std;

Student :: Student()
{
ID = 0;
first_name = "";
last_name = "";
date_of_birth = "";
address = "";
  
}

void Student :: setStudent(int ID, string first_name, string last_name, string date_of_birth, string address, int code, string phn)
{
this -> ID = ID;
this -> first_name = first_name;
this -> last_name = last_name;
this -> date_of_birth = date_of_birth;
this -> address = address;
this -> area_code = code;
this -> telephone_number = phn;
}

int Student :: getID()
{
return ID;
}

void Student :: setID(int ID)
{
this -> ID = ID;
}

string Student :: getFirstName()
{
return first_name;
}

void Student :: setFirstName(string name)
{
this -> first_name = name;
}

void Student :: setLastName(string name)
{
this -> last_name = name;
}

string Student :: getLastName()
{
return last_name;
}

void Student :: setAddress(string addr)
{
this -> address = addr;
}

string Student :: getAddress()
{
return address;
}

void Student :: setDOB(string dob)
{
this -> date_of_birth = dob;
}

string Student :: getDOB()
{
return date_of_birth;
}

string Student :: getFullName()
{
return first_name+last_name;
}

string Student :: getTelephoneNumber()
{
string tele = "" + area_code;
tele += "(" + telephone_number + ")";
return tele;
}

void Student :: setTelephoneNumber(int code, string phn)
{
this -> area_code = code;
this -> telephone_number = phn;
}

bool Student :: sameLastName(Student s2)
{
if(s2.last_name.compare(this->last_name) != 0) {
return false;
}
return true;
}

bool Student :: sameAddress(Student s2)
{
if(s2.address.compare(this->address) !=0 ) {
return false;
}
return true;
}

main.cpp:


#include <stdio.h>
#include <iostream>
#include "student.h"
#include <string>

using namespace std;

int main()
{
Student s1;
//s1.setStudent(1, "Ram", "Mohan", "06/10/1990", "Dallas", 469, "613967");
Student s2;
//s1.setStudent(1, "John", "Lands", "22/03/1991", "San Antonio", 210, "723490");
  
string fn1,fn2,sn1,sn2,addr1,addr2,tlph1,tlph2,dob1,dob2;
int id1, id2, c1,c2;
cout << "Enter Student 1 details:\n";
cout << "Enter Students first name:\n";
cin >> fn1;
cout << "Enter Students second name:\n";
cin >> sn1;
cout << "Enter Students id:\n";
cin >> id1;
cout << "Enter Students address: \n";
cin >> addr1;
cout << "Enter Students DOB: \n";
cin >> dob1;
cout << "Enter Students area code: \n";
cin >> c1;
cout << "Enter Students telephone number:\n";
cin >> tlph1;
s1.setStudent(id1, fn1, sn1, dob1, addr1, c1, tlph1);
  
cout << "Enter Student 2 details:\n";
cout << "Enter Students first name:\n";
cin >> fn2;
cout << "Enter Students second name:\n";
cin >> sn2;
cout << "Enter Students id:\n";
cin >> id2;
cout << "Enter Students address: \n";
cin >> addr2;
cout << "Enter Students DOB: \n";
cin >> dob2;
cout << "Enter Students area code: \n";
cin >> c2;
cout << "Enter Students telephone number:\n";
cin >> tlph2;
s2.setStudent(id2, fn2, sn2, dob2, addr2, c2, tlph2);
  
bool slast_name = s1.sameLastName(s2);
if(slast_name) {
cout << "Both students have same last name." <<endl;
} else {
cout << "The students do not have the same last name." << endl;
}
  
bool saddress = s1.sameAddress(s2);
if(saddress) {
cout << "Both the Students are roommates." << endl;
} else {
cout << "The Students are not roommates." << endl;
}
  
return 0;
}

Sample Output:

Enter Student 1 details:
Enter Students first name:
Ram
Enter Students second name:
Mohan
Enter Students id:
1
Enter Students address:
Dallas
Enter Students DOB:
06/05/1992
Enter Students area code:
469
Enter Students telephone number:
617890
Enter Student 2 details:
Enter Students first name:
Laxman
Enter Students second name:
Mohan
Enter Students id:
2
Enter Students address:
Dallas
Enter Students DOB:
16/12/1991
Enter Students area code:
469
Enter Students telephone number:
789324
Both students have same last name.
Both the Students are roommates.

Add a comment
Know the answer?
Add Answer to:
Use C++ to create a class called Student, which represents the students of a university. A...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • *** C++ *** Create a class called Student that contains a first name ( string) and...

    *** C++ *** Create a class called Student that contains a first name ( string) and an student id number (type long).     1. Include a member function called get_data( ) to get data from the user for insertion into the object,     2. Also include a function called display_data( ) that displays the student data. Then write a complete program that uses the class to do some computation. Your main function, main( ), should create a Dynamic Array of...

  • Complete Course.cpp by implementing the PrintRoster() function, which outputs a list of all students enrolled in a course and also the total number of students in the course.

    Complete Course.cpp by implementing the PrintRoster() function, which outputs a list of all students enrolled in a course and also the total number of students in the course.Given files: main.cpp - contains the main function for testing the program.Course.cpp - represents a course, which contains a vector of Student objects as a course roster. (Type your code in here)Course.h - header file for the Course class.Student.cpp - represents a classroom student, which has three data members: first name, last name, and...

  • about this question 2, I don't know how to do it in C++, can anyone help...

    about this question 2, I don't know how to do it in C++, can anyone help me out??? C 38s. A &X C Solved Get Hon (246) Th (242) A X PowerPo X X endrc Microso odle.concordia.ca/moodle/pluginfile.php/3796501/mod resource/content/1/A4 % 20- %20F2019 pdf COEN 243-Fall 2019 2. (25 marks) Define a class called "House", that represents the information of a house. A House is defined with these attributes: age (int), type (string) (Detached, Semi-Attached, Attached), rooms (int) and cost (double). Functions...

  • Create a java class for an object called Student which contains the following private attributes: a...

    Create a java class for an object called Student which contains the following private attributes: a given name (String), a surname (family name) (String), a student ID number (an 8 digit number, String or int) which does not begin with 0. There should be a constructor that accepts two name parameters (given and family names) and an overloaded constructor accepting two name parameters and a student number. The constructor taking two parameters should assign a random number of 8 digits....

  • Write a C++ program that includes the following: Define the class Student in the header file Stu...

    Write a C++ program that includes the following: Define the class Student in the header file Student.h. #ifndef STUDENT_H #define STUDENT_H #include <string> #include <iostream> using namespace std; class Student { public: // Default constructor Student() { } // Creates a student with the specified id and name. Student(int id, const string& name) { } // Returns the student name. string get_name() const { } // Returns the student id. int get_id () const { } // Sets the student...

  • Files given in this assignment (right-click on the file to download) Assignment7.cpp (need to complete) Student.h...

    Files given in this assignment (right-click on the file to download) Assignment7.cpp (need to complete) Student.h (Given. Just use it, don't change it!) Student.cpp (Partially filled, need to complete) 1. Assignment description In this assignment, you will write a simple class roster management system for ASU CSE100. Step #1: First, you will need to finish the design of class Student. See the following UML diagram for Student class, the relevant header file (class declaration) is given to you as Student.h,...

  • Create a class hierarchy to be used in a university setting. The classes are as follows:...

    Create a class hierarchy to be used in a university setting. The classes are as follows: The base class is Person. The class should have 3 data members: personID (integer), firstName(string), and lastName(string). The class should also have a static data member called nextID which is used to assign an ID number to each object created (personID). All data members must be private. Create the following member functions: o Accessor functions to allow access to first name and last name...

  • could you solve this in C++ please 2. (25 marks) Define a class called "House", that...

    could you solve this in C++ please 2. (25 marks) Define a class called "House", that represents the information of a house. A House is defined with these attributes: age (int), type (string) (Detached, Semi-Attached, Attached), rooms (int) and cost (double). Functions of the House class must perform the following operations: • Return the house age • Modify the house age • Return the house type • Return the number of rooms • A function called estimate Price() that returns...

  • I need code in java The Student class: CODE IN JAVA: Student.java file: public class Student...

    I need code in java The Student class: CODE IN JAVA: Student.java file: public class Student {    private String name;    private double gpa;    private int idNumber;    public Student() {        this.name = "";        this.gpa = 0;        this.idNumber = 0;    }    public Student(String name, double gpa, int idNumber) {        this.name = name;        this.gpa = gpa;        this.idNumber = idNumber;    }    public Student(Student s)...

  • C++ Design: Create a UML Class diagram that reflects the software design of your entire program...

    C++ Design: Create a UML Class diagram that reflects the software design of your entire program Q3. Create a class called Passenger that represents passengers of an airline company. A passenger is defined by the following information: - Passenger ID (int) - Name (string) - Address (string) - Tel (string) - Date of birth (of type Date from Q2) Provide the following functions: - A constructor that initializes the data members and provides default arguments. - Accessor methods that return...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT