Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Last night I had to edit very similar code but as a struct. Tonight I have to edit the similar code but as a Class.

Last night I had to edit very similar code but as a struct. Tonight I have to edit the similar code but as a Class. There is some code missing and i am struggling to figure out what lines are missing.

CURRENT CODE:

#include using std::cin; using std::cout; using std::endl;

// Declare a simple class to hold a date. class Date { private: int month; int day; public: int year; void fill(void ); void show(void ); };

// A Date can be used as a component of another class class Person { public: int height; int weight; Date birthday; void show(void); };

int main() { Date first; // Declaration with no initialization.

cout << endl; first.fill(); // Here is initialization with a member function. cout << " Printing the date:" << endl; first.show(); // Then display the results for either.

Person Joe; // Some examples for manipulating a person Joe.height=72; // Because these fields are public, we have direct access. Joe.weight=180; cout << endl; Joe.birthday.fill(); cout << " Joe was born in " << Joe.birthday.year << endl; cout << "Here's Joe:" << endl; Joe.show(); cout << endl;

return(0); }

// Here are the member function definitions. Note use of scoping operator :: void Date::fill(void) { int tmp; // Enter the month with some verification of data. do { cout << "Enter month as integer 1-12: "; cin >> tmp; } while( tmp<1 || tmp>12); month=tmp; // Enter the day, limited verification. do { cout << "Enter day as integer 1-31: "; cin >> tmp; } while( tmp<1 || tmp>31); day=tmp; cout << "Enter year as integer: "; cin >> year; cout << "You entered this date: \t"; show(); }

void Date::show(void) { cout << month << "/" << day << "/" << year << endl; }

void Person::show(void) { cout << "Height is " << height << endl << "Weight is " << weight << endl

<< "Birthday is "; birthday.show(); }

WHAT THE CODE NEEDS TO DISPLAY:

Enter month as integer 1-12: 3

Enter day as integer 1-31: 21

Enter year as integer: 2002

Printing the date:

3/21/2002

Birthday:

Enter month as integer 1-12: 5

Enter day as integer 1-31: 19

Enter year as integer: 1993

Measure date:

Enter month as integer 1-12: 10

Enter day as integer 1-31: 6

Enter year as integer: 1962

Joe was born in 1993

And here is Joe:

Height is 72

Weight is 180

Last measured on 10/6/1962

Birthday is 5/19/1993

Joe was last measured in 1962

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transact SQL Cookbook Help For Database Programmers

Authors: Ales Spetic, Jonathan Gennick

1st Edition

1565927567, 978-1565927568

More Books

Students also viewed these Databases questions