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

Posted on 2006-04-05
Last Modified: 2010-04-01
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;;
      std::cout << "Please enter your DOB:" << std::endl;;


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;;
std::cout << "Please enter values for Box 2: " << std::endl;;
std::cout << "Please enter values for Box 3: " << std::endl;;

Question by:goretailpro
    LVL 20

    Assisted Solution

    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?

    LVL 12

    Accepted Solution

    In your code there are lots of 'public' specifier
    So many public is not required. One is enough.
    Something like this

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

               void read(){
               // ...

               void print() {
               // ...

    Do the same for class Box.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
    Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
    The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
    The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now