[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 182
  • Last Modified:

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()

0
goretailpro
Asked:
goretailpro
2 Solutions
 
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
 
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now