Question

In: Computer Science

This is what I have so far. The out print I am looking for is Date...

This is what I have so far.

The out print I am looking for is

Date is 7/22/2020

New month: 9

New day: 5

New Year: 2020

Date is 9/5/2020

#include

  
class Date {
   public:
       Date::Date(int dateMonth, int dateDay, int dateYear)
       month{dateMonth}, day{dateDay}, int dateYear}{}
      
       //void displayDate();     
   //set month
       void Date::setMonth(std::int dateMonth){
           month = dateMonth;
       }
       //retrieve month
       std:: string getMonth() {
           return month;
       }
      
          
       //set day
       void setDay(std::int dateDay){
           day = dateDay;
       }
       //Retrieve day
       std:: string getDay() {
           return day;
       }
      
       ;
   //set year
       void setYear(std::int dateYear){
           year = dateYear;
       }
       //retrieve year
       std:: int getYear() {
           return year;
       }
  
  
   private:
  
       std::int day;
       std::int month;
       std::int year;
      
      

      
};

#include <iostream>
#include<string>
#include "Date.h"

using namespace std;

int main() {
   Date myMonth{};
  
   cout<<"Date is: " ;

   cout<<"\nNew month: ";
   string theMonth;
   getline(cin, theMonth);
   myMonth.setMonth(theMonth);
          
       Date myDay;  
      
   cout<<"New day: ";
   string theDay;
   getline(cin, theDay);
   myDay.setDay(theDay);
  
   Date myYear;  
      
   cout<<"New year: ";
   string theYear;
   getline(cin, theYear);
   myYear.setYear(theYear);
  
   cout<<"Date is: "<< theMonth <<"/" <<theDay<< "/"<< theYear;
      
  
  
}

Solutions

Expert Solution

Date.h

#ifndef DATE_H
#define DATE_H
#include<iostream>
class Date {
   public:
           Date(){day=month=year=0;};
       Date(int dateMonth, int dateDay, int dateYear){
        month = dateMonth;
                day = dateDay; 
                year = dateYear;
        }
      
      //display date
       void displayDate(){
         std::cout<<"Date is "<<month<<"/"<<day<<"/"<<year<<std::endl;
           }   
        //set month
       void setMonth(int dateMonth){
           month = dateMonth;
       }
       //retrieve month
       int getMonth() {
           return month;
       }
      
       //set day
       void setDay(int dateDay){
           day = dateDay;
       }
       //Retrieve day
       int getDay() {
           return day;
       }
      
       ;
   //set year
       void setYear(int dateYear){
           year = dateYear;
       }
       //retrieve year
       int getYear() {
           return year;
       }
  
  
   private:
                int day;
       int month;
       int year;    
};

#endif

mainDriver.cpp

#include <iostream>
#include<string>
#include "Date.h"

using namespace std;

int main() {
   Date oldDate(7,22,2020);
   oldDate.displayDate() ;

   Date newDate;
   
   cout<<"New month: ";
   int theMonth;
   cin >> theMonth;
   
   newDate.setMonth(theMonth);
      
   cout<<"New day: ";
   int theDay;
   cin >> theDay;
   
   newDate.setDay(theDay);
      
   cout<<"New year: ";
   int theYear;
   cin >> theYear;
   
   newDate.setYear(theYear);
  
   newDate.displayDate();
  
}

How to Test and Run:(Unix or Linux machine)

Put both files (Date.h and mainDriver.cpp) in the same folder or directory. Go to that directory in the terminal and run below command one by one.

       g++ mainDriver.cpp

       ./a.out

On Window, you can compile and run the file mainDriver.cpp in any c++ compiler or IDE after putting both the files in the same directory.

Output:

Windows                                                   Linux


Related Solutions

Looking to see how to figure this out. So far when I break apart the coding...
Looking to see how to figure this out. So far when I break apart the coding it works but when it is all together it doesn't, Hangman We're going to write a game of hangman. Don't worry, this assignment is not nearly as difficult as it may appear. The way hangman works (for this assignment - we are doing a simplified game) is as follows: the computer will choose a word. (For this version, a word is selected from a...
As CEO of WeCare, I am happy with what we have done so far advancing patient...
As CEO of WeCare, I am happy with what we have done so far advancing patient safety. The Diagnostic Errors concern for us is being managed. Now it is time to look at a second concern and move closer to becoming a High-Reliability Organization. The next executive briefing concern that I want to have addressed – Internal Care Coordination. Communication seems to be a big piece of this, so I want us to understand what this means. What do we...
Here is what I have so far. I have created a code where a user can...
Here is what I have so far. I have created a code where a user can enter in their information and when they click submit all of the information is shown. How can I add a required field for the phone number without using an alert? <!Doctype html> <html> <head> <meta charset="UTF-8"> <title>Login and Registeration Form Design</title> <link rel="stylesheet" type="text/css" href="signin.css"> <script> function myFunction(){ document.getElementById('demo').innerHTML = document.getElementById('fname').value + " " + document.getElementById('lname').value + " " + document.getElementById('street').value + " "...
Write a program to print the number of class assignments you have done so far, the...
Write a program to print the number of class assignments you have done so far, the total grades, and average grade. Prompt a 0 input to end the program. Java Using while statements in the lecture this was provided. Wording confused me, Total grade is sum of all grades.
How to schematize a diagnostic argument? This is what i have so far not sure if...
How to schematize a diagnostic argument? This is what i have so far not sure if its right, need help with this one in order to figure out rest of homework. ----------- IQ: Is drinking milk healthy? (5 items of Support TD or NTD) S1: S2: S3: S4: S5: C1: More than half of the population in north America are lactose intolerant meaning they cannot digest milk properly. C2: Article: https://milk.procon.org/
I have solved most of question and the answers I have so far are correct, I...
I have solved most of question and the answers I have so far are correct, I just need help finding out the lower bound and upper bound (All answers were generated using 1,000 trials and native Excel functionality.) Galaxy Co. distributes wireless routers to Internet service providers. Galaxy procures each router for $75 from its supplier and sells each router for $125. Monthly demand for the router is a normal random variable with a mean of 100 units and a...
I drive to school and am currently looking for a parking spot so I can walk...
I drive to school and am currently looking for a parking spot so I can walk to Jacob's. If I turn into a parking lot to look for a spot to park in that specific lot, the process of looking for a spot takes 1 minute of time whether I find a spot or not.   Parking lot A is closest to Jacobs. If I get a spot here, it takes me 1 minute to walk into my class at the...
This is a nice question when you find it out, and I am really looking for...
This is a nice question when you find it out, and I am really looking for a proper answer. Take quicksilver (Hg) in the periodic table. It has one proton more than Gold (melting point 1337.33 K), and one less than Thallium (melting point 577 K). It belongs to the same group as Zinc (692.68 K) and Cadmium (594.22 K). All not very high melting points, but still dramatically higher than quicksilver (234.32 K). When his neighbors melt, quicksilver vaporizes...
So I was looking out the sky one day and I wondered how I would go...
So I was looking out the sky one day and I wondered how I would go about calculating how much water was contained in a cloud. I figured the following simple outline 1) We need to roughly know how big it is. We'll also be figuring out how high the cloud is. Use some sort of geometric method? Triangles? 2) We need to relate its color to its density. (Darker clouds more dense) (White fluffy clouds less dense) 3) Correction...
The code following is what I have so far. It does not meet my requirements. My...
The code following is what I have so far. It does not meet my requirements. My problem is that while this program runs, it doesn't let the user execute the functions of addBook, isInList or compareLists to add, check, or compare. Please assist in correcting this issue. Thank you! Write a C++ program to implement a singly linked list of books. The book details should include the following: title, author, and ISBN. The program should include the following functions: addBook:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT