I need help getting this code to work and how to do it also..

I am suppose to create a class Box and test it as in the example date.cpp.

Here is date.cpp:

"

#include <iostream>
class Date {
public:            int mm;
public:            int dd;
public:            int yy;
public:      void read(){
      std::cout << "Please enter the month: \a" ;
      std::cin >> mm;

      std::cout << "Please enter the day: \a" ;
      std::cin >> dd;

      std::cout << "Please enter the year: \a" ;
      std::cin >> yy;
      }
public:      void print() {
            std::cout << mm << "/" << dd << "/" << yy << std::endl;
      }
};

void main() {
      Date myDOB;
      Date yourDOB;
      std::cout << "Please enter my DOB:" << std::endl;
    myDOB.read();
      std::cout << "Please enter your DOB:" << std::endl;
    yourDOB.read();
      myDOB.print();
      yourDOB.print();
}

"

class Box {
            public:  int W;
            public:  int L;
            public:  int H;
public: void read(){
                            // implement read in data members
                            }
public: void print() {
                           // implement print out data members
                             }

}; // end of class, note there is a semicolon after the close brace
 

To test your class, write the following test statements in your main() function:

Box b1;
Box b2;
Box b3;
std::cout << "Please enter values for Box 1: " << std::endl;
b1.read();
std::cout << "Please enter values for Box 2: " << std::endl;
b2.read();
std::cout << "Please enter values for Box 3: " << std::endl;
b3.read();
b1.print();
b2.print();
b3.print()

goretailproAsked:
Who is Participating?
 
rajeev_devinCommented:
In your code there are lots of 'public' specifier
So many public is not required. One is enough.
Something like this

class Date {
public:
           int mm;
           int dd;
           int yy;

           void read(){
           // ...
           }

           void print() {
           // ...
           }
};

Do the same for class Box.
0
 
ikeworkCommented:
hi goretailpro,

everything you need is already written in class Date. you only need to adapt that. do you understand how the Date::read() - memberfunction works?

ike
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.