Question

HW_8b - Famous People - One class used by another class - This exercise requires the declaration of two classes: o Famous PeoFile: Date.h Private data members: O _month o _day 0 year - Public member functions: o Default constructor • Assign Os to alo displayDate • An objects date is displayed. File: Date.cpp - Function definitions for all Date class member functions Fileo setQuote • A famous quotation is passed as an argument and assigned to an objects data member o setDate • The arguments pa_birthdate.displayDate(); File: FamousPeople.cpp - Function implementations for all FamousPeople class member functions File:display the birthdate. (see output) o Output the other two famous people. (see output) /* OUTPUT: Enter the first famous persYear: 1879 --- (Screen Clears) -- Enter the third famous person: Hitler Enter the quotation: What luck for the rulers that merefuse military service. Name: Hitler Birth Date: 4/20/1889 Enter the quotation: What luck for the rulers that men do not t

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code is as follows:

Date.h

#ifndef DATE_H
#define DATE_H
#include<iostream>
using namespace std;

class Date
{
public:
Date();//default constructor
Date(int,int,int); //parametrized constructor
~Date(); //destructor
void setDate(int,int,int); //set date of the object
void displayDate(); //display the date

private:
int month; //private members of the class
int day;
int year;
};

#endif // DATE_H

Screenshot of the code:

FamousPeople.hFamous People.cpp main.cpp D ate. h Date.cpp 1 #ifndef DATE_H #define DATE H 3 #include<iostream> 4 using names

***********************************************************************************************************************************

Date.cpp

#include "Date.h"

Date::Date()
{
month=0;
day=0;
year=0;
}

Date::Date(int month,int day,int year)
{
//set all the members
this->month=day;
this->day=day;
this->year=year;
}

void Date::setDate(int month,int day,int year){
//set the date
this->month=month;
this->day=day;
this->year=year;
}

void Date::displayDate(){
//display Date
cout<<month<<"/"<<day<<"/"<<year;
}
Date::~Date()
{
}

Screenshot of the code:

Famous People.h Famous People.cpp: main.cpp Dateh Date.cpp 1 #include Date.h 3 Date::Date() 4- { month=0; day=0; year=0; 8

***********************************************************************************************************************************

FamousPeople.h

#ifndef FAMOUSPEOPLE_H
#define FAMOUSPEOPLE_H

#include "Date.h"

class FamousPeople
{
public:
FamousPeople();//default constructor
~FamousPeople();//parametrized constructor
void setName(string); //setters for all members
void setQuote(string);
void setDate(int,int,int);
void displayDate(); //displayDate
void displayPerson(); //displayPerson
private:
string name; //private members
string quote;
Date birthdate;
};

#endif // FAMOUSPEOPLE_H

Screenshot of the code:

Famous People.h! Famous People.cpp main.cpp Dateh Date.cpp 1 #ifndef FAMOUSPEOPLE H 2 #define FAMOUSPEOPLE H 4 #include Date

***********************************************************************************************************************************

FamousPeople.cpp

#include "FamousPeople.h"


FamousPeople::FamousPeople()
{
name=""; //constructor
quote="";
birthdate.setDate(0,0,0);
}


void FamousPeople::setName(string name){
this->name = name; //set the name
}
void FamousPeople:: setQuote(string quote){
this->quote = quote; //set the quote
}
void FamousPeople:: setDate(int month,int day,int year){
birthdate.setDate(month,day,year); //set the date
}

//displayPerson
void FamousPeople::displayPerson(){
cout<<"Name: "<<name<<endl;
cout<<"Birth Date: ";
displayDate();
cout<<endl;
cout<<"Enter the quotation: "<<endl;
cout<<"\""<<quote<<"\""<<endl;
}

//displayDate
void FamousPeople::displayDate(){
birthdate.displayDate();
}
FamousPeople::~FamousPeople()
{
}

Screenshot of the code:

Famous People.h! Famous People.cpp: main.cpp Date. h D ate.cpp 1 #include Famous People.h Famous People:: FamousPeople() na

***********************************************************************************************************************************

main.cpp

#include<iostream>
#include <stdlib.h>
using namespace std;
#include "FamousPeople.h"
int main(){
  
FamousPeople people1; //first person object
string name;
string quotation;
int month,day,year;
  
cout<<"\nEnter the first famous person : ";
getline(cin, name); //get first person name
people1.setName(name); //set the name
cout<<"\nEnter the quotation:"<<endl;
getline(cin, quotation); //get quotation
people1.setQuote(quotation); //set quotation
cout<<"\nEnter the birthdate:"<<endl;
cout<<"Month: ";
cin>>month; //get month
cout<<"Day: ";
cin>>day; //get day
cout<<"Year: ";
cin>>year; //get year
people1.setDate(month,day,year); //set the date
system("clear");
  
//same as above for the next two people
cin.ignore();
FamousPeople people2;
cout<<"\nEnter the second famous person : ";
getline(cin, name);
people2.setName(name);
cout<<"\nEnter the quotation:"<<endl;
getline(cin, quotation);
people2.setQuote(quotation);
cout<<"\nEnter the birthdate:"<<endl;
cout<<"Month: ";
cin>>month;
cout<<"Day: ";
cin>>day;
cout<<"Year: ";
cin>>year;
people2.setDate(month,day,year);
system("clear");
  
cin.ignore();
FamousPeople people3;
cout<<"\nEnter the third famous person : ";
getline(cin, name);
people3.setName(name);
cout<<"\nEnter the quotation:"<<endl;
getline(cin, quotation);
people3.setQuote(quotation);
cout<<"\nEnter the birthdate:"<<endl;
cout<<"Month: ";
cin>>month;
cout<<"Day: ";
cin>>day;
cout<<"Year: ";
cin>>year;
people3.setDate(month,day,year);
system("clear");
  
cout<<"Here are some famous people:"<<endl<<endl;
people1.displayPerson();
cout<<endl;
people2.displayPerson();
cout<<endl;
people3.displayPerson();
cout<<endl;
  
return 0;
}

Screenshot of the code:

1 #include<iostream> 2 #include <stdlib.h> 3 using namespace std; 4. #include Famous People.h int main(){ 5- U/first personcin>>month; cout<<Day: ; cin>>day; cout<<Year: ; cin>>year; people2.setDate(month, day, year); system(clear); cin.ignor

Output:

Enter the first famous person : Davinci Enter the quotation: I have from an early age abjured the use of meat, and the time wScreen cleared

Enter the second famous person : Einstein Enter the quotation: The pioneers of a warless world are the youth who refuse milit

Screen cleared

Enter the third famous person : Hitler Enter the quotation: What luck for the rulers that men do not think. Enter the birthda

Screen cleared

WILDU PEUPie. Name: DaVinci Birth Date: 4/15/1452 Enter the quotation: I have from an early age abjured the use of meat, and

Add a comment
Know the answer?
Add Answer to:
HW_8b - Famous People - One class used by another class - This exercise requires the...
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
  • - Classes Write a C++ program that creates a class called Date that includes three pieces...

    - Classes Write a C++ program that creates a class called Date that includes three pieces of information as data members, namely:  month (type int)  day (type int)  year (type int). Program requirements: - Provide set and a get member functions for each data member. - For the set member functions assume that the values provided for the year and day are correct, but in the setMonth member function ensure that the month value is in the...

  • Part I: (The Myate class) Design a class named MyDate. The class contains: • The data...

    Part I: (The Myate class) Design a class named MyDate. The class contains: • The data fields year, month, and day that represent a date. Month is 0-based, i.e., 0 is for January. • A no-arg constructor that creates a MyDate object for the current date. • A constructor that constructs a MyDate object with a specified elapsed time since midnight, January 1, 1970, in milliseconds. • A constructor hat constructs a MyDate object with the specified year, month, and...

  • The class dateType is designed to implement the date in a program, but the member function...

    The class dateType is designed to implement the date in a program, but the member function setDate and the constructor do not check whether the date is valid before storing the date in the data members. Rewrite the definitions of the function setDate and the constructor so that the values for the month, day, and the year are checked before storing the date into the data members. Add a function member, isLeapYear, to check whether a year is a leap...

  • In JAVA 1. Create a class called Rectangle that has integer data members named - length...

    In JAVA 1. Create a class called Rectangle that has integer data members named - length and width. Your class should have a default constructor (no arg constructor) Rectangle() that initializes the two instance variables of the object Rect1. The second overloading constructor should initializes the value of the second object Rect2. The class should have a member function named GetWidth() and GetLength() that display rectangle's length and width. OUTPUT: Rectl width: 5 Rectl length: 10 Enter a width :...

  • In C++, Step 1: Implement the Student Class and write a simple main() driver program to...

    In C++, Step 1: Implement the Student Class and write a simple main() driver program to instantiate several objects of this class, populate each object, and display the information for each object. The defintion of the student class should be written in an individual header (i.e. student.h) file and the implementation of the methods of the student class should be written in a corresponding source (i.e. student.cpp) file. Student class - The name of the class should be Student. -...

  • C++ Programing In this exercise, you will design a class memberType. The class has the following...

    C++ Programing In this exercise, you will design a class memberType. The class has the following data members: memberName. A string that holds the name of a person memberID. A string that holds the member identification number numBooks. An int that holds the number of books bought purchaseAmt. A double that holds the amount spent on books In addition, the class should have the following constructor and other member functions. Constructor. The constructor should accept the person’s name and member...

  • 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...

  • A class allows a group of one or more member objects to have a series of...

    A class allows a group of one or more member objects to have a series of common characteristics and functions. Create a class (student) that contains the member characteristics: Student ID (string) Student Last Name (string) Student First Name (string) GPA (float) Number of enrolled classes (integer) The class functions are: setID (string passed to function to set Student ID) setLastName (string passed to function to set Student Last Name) setFirstName (string passed to function to set Student First Name)...

  • Tasks A. (20 po ints) In Lab 6, you defined and implemented a class called Date....

    Tasks A. (20 po ints) In Lab 6, you defined and implemented a class called Date. You will make some modific ation to the Date class so that it mccts the folowing specific ations: The Date class consists of three private member variables: Member Variable year month day Description An int variable that hokls the value of a year. An int variable that hokds the value of a month An int variable that hokis the value of a day. The...

  • Write a class named Month. The class should have an int field named monthNumber that holds...

    Write a class named Month. The class should have an int field named monthNumber that holds the number of the month. For example. January would be 1. February would be 2. and so forth. In addition, provide the following methods A no-arg constructor that sets the monthNumber field to 1 A constructor that accepts the number of the month as an argument. It should set the monthNumber field to the value passed as the argument. If a value less than...

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