1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Blizzard [7]
2 years ago
6

The class dateType was designed to implement the date in a program, but the member function setDate and the constructor do not c

heck whether the date is valid before storing the date in the member variables. Rewrite the definitions of the function setDate and the constructor so that the values for the month, day, and year are checked before storing the date into the member variables. Add a member function, isLeapYear, to check whether a year is a leap year. Moreover, write a test program to test your class. Input should be format month day year with each separated by a space. Output should resemble the following:
Computers and Technology
2 answers:
ivanzaharov [21]2 years ago
5 0

Answer:

Check the explanation

Explanation:

Code:

dateType.h

#ifndef dateType_H

#define dateType_H

class dateType

{

public:

   void setDate(int month, int day, int year);

     //Function to set the date.

     //The member variables dMonth, dDay, and dYear are set

     //according to the parameters.

     //Postcondition: dMonth = month; dDay = day;

     //               dYear = year

   int getDay() const;

     //Function to return the day.

     //Postcondition: The value of dDay is returned.

   int getMonth() const;

     //Function to return the month.

     //Postcondition: The value of dMonth is returned.

   int getYear() const;

     //Function to return the year.    

     //Postcondition: The value of dYear is returned.

   void printDate() const;

     //Function to output the date in the form mm-dd-yyyy.

  void isLeapYear() const;

   dateType(int month = 1, int day = 1, int year = 1900);

     //Constructor to set the date

     //The member variables dMonth, dDay, and dYear are set

     //according to the parameters.

     //Postcondition: dMonth = month; dDay = day; dYear = year;

     //               If no values are specified, the default

     //               values are used to initialize the member

     //               variables.

private:

   int dMonth; //variable to store the month

   int dDay;   //variable to store the day

   int dYear; //variable to store the year

};

#endif

dateType.cpp

#include <iostream>

#include "dateType.h"

using namespace std;

void dateType::setDate(int month, int day, int year)

{

  // Checking month is valid

  while(month<1 || month>12)

  {

      cout << "Enterd month "<<month<< " is wrong"<<endl;

      cout << "Enter correct month"<<endl;

      cin>>month;

  }

  dMonth = month;

 

  // Checking date is valid

  while(day<1 || day>31)

  {

      cout << "Enterd date "<<day<<" is wrong"<<endl;

      cout<<"Enter correct date"<<endl;

      cin>>day;

  }

  dDay = day;

  int count_digits = 0;

  int flag=0;

  int year1;

  // Counting number of digits in year

   while(flag==0)

  {

      year1=year;

      count_digits=0;

      while (year) {

          year /= 10;

          count_digits++;

      }

      if(count_digits != 4)

      {

          cout << "Enterd year "<<year1<<" is wrong"<<endl;

          cout<<"Enter correct year"<<endl;

          cin>>year;

          flag=0;

      }

      else

          flag=1;

  }

  dYear = year1;

}

 

int dateType::getDay() const

{

   return dDay;

}

int dateType::getMonth() const

{

   return dMonth;

}

int dateType::getYear() const

{

   return dYear;

}

void dateType::printDate() const

{

   cout << dMonth << "-" << dDay << "-" << dYear;

}

void dateType::isLeapYear() const

{

 

if ( dYear%400 == 0)

   cout<<endl<<dYear<< " is leap year.\n";

else if ( dYear%100 == 0)

   cout<<endl<<dYear<< " is leap year.\n";

else if ( dYear%4 == 0 )

   cout<<endl<<dYear<< " is leap year.\n";

else

   cout<<endl<<dYear<< " is not leap year.\n";

}

   //Constructor with parameters

dateType::dateType(int month, int day, int year)

{

  // Checking month is valid

  while(month<1 || month>12)

  {

      cout << "Enterd month "<<month<< " is wrong"<<endl;

      cout << "Enter correct month"<<endl;

      cin>>month;

  }

  dMonth = month;

 

  // Checking date is valid

  while(day<1 || day>31)

  {

      cout << "Enterd date "<<day<<" is wrong"<<endl;

      cout<<"Enter correct date"<<endl;

      cin>>day;

  }

  dDay = day;

  int count_digits = 0;

  int flag=0;

  int year1;

  // Counting number of digits in year

   while(flag==0)

  {

      year1=year;

      count_digits=0;

      while (year) {

          year /= 10;

          count_digits++;

      }

      if(count_digits != 4)

      {

          cout << "Enterd year "<<year1<<" is wrong"<<endl;

          cout<<"Enter correct year"<<endl;

          cin>>year;

          flag=0;

      }

      else

          flag=1;

  }

  dYear = year1;

}

#include<iostream>

#include "dateType.h"

using namespace std;

int main()

}

}

san4es73 [151]2 years ago
4 0

Answer:

see explaination

Explanation:

dateType.h

#ifndef dateType_H

#define dateType_H

class dateType

{

public:

void setDate(int month, int day, int year);

//Function to set the date.

//The member variables dMonth, dDay, and dYear are set

//according to the parameters.

//Postcondition: dMonth = month; dDay = day;

// dYear = year

int getDay() const;

//Function to return the day.

//Postcondition: The value of dDay is returned.

int getMonth() const;

//Function to return the month.

//Postcondition: The value of dMonth is returned.

int getYear() const;

//Function to return the year.

//Postcondition: The value of dYear is returned.

void printDate() const;

//Function to output the date in the form mm-dd-yyyy.

void isLeapYear() const;

dateType(int month = 1, int day = 1, int year = 1900);

//Constructor to set the date

//The member variables dMonth, dDay, and dYear are set

//according to the parameters.

//Postcondition: dMonth = month; dDay = day; dYear = year;

// If no values are specified, the default

// values are used to initialize the member

// variables.

private:

int dMonth; //variable to store the month

int dDay; //variable to store the day

int dYear; //variable to store the year

};

#endif

dateType.cpp

#include <iostream>

#include "dateType.h"

using namespace std;

void dateType::setDate(int month, int day, int year)

{

// Checking month is valid

while(month<1 || month>12)

{

cout << "Enterd month "<<month<< " is wrong"<<endl;

cout << "Enter correct month"<<endl;

cin>>month;

}

dMonth = month;

// Checking date is valid

while(day<1 || day>31)

{

cout << "Enterd date "<<day<<" is wrong"<<endl;

cout<<"Enter correct date"<<endl;

cin>>day;

}

dDay = day;

int count_digits = 0;

int flag=0;

int year1;

// Counting number of digits in year

while(flag==0)

{

year1=year;

count_digits=0;

while (year) {

year /= 10;

count_digits++;

}

if(count_digits != 4)

{

cout << "Enterd year "<<year1<<" is wrong"<<endl;

cout<<"Enter correct year"<<endl;

cin>>year;

flag=0;

}

else

flag=1;

}

dYear = year1;

}

int dateType::getDay() const

{

return dDay;

}

int dateType::getMonth() const

{

return dMonth;

}

int dateType::getYear() const

{

return dYear;

}

void dateType::printDate() const

{

cout << dMonth << "-" << dDay << "-" << dYear;

}

void dateType::isLeapYear() const

{

if ( dYear%400 == 0)

cout<<endl<<dYear<< " is leap year.\n";

else if ( dYear%100 == 0)

cout<<endl<<dYear<< " is leap year.\n";

else if ( dYear%4 == 0 )

cout<<endl<<dYear<< " is leap year.\n";

else

cout<<endl<<dYear<< " is not leap year.\n";

}

//Constructor with parameters

dateType::dateType(int month, int day, int year)

{

// Checking month is valid

while(month<1 || month>12)

{

cout << "Enterd month "<<month<< " is wrong"<<endl;

cout << "Enter correct month"<<endl;

cin>>month;

}

dMonth = month;

// Checking date is valid

while(day<1 || day>31)

{

cout << "Enterd date "<<day<<" is wrong"<<endl;

cout<<"Enter correct date"<<endl;

cin>>day;

}

dDay = day;

int count_digits = 0;

int flag=0;

int year1;

// Counting number of digits in year

while(flag==0)

{

year1=year;

count_digits=0;

while (year) {

year /= 10;

count_digits++;

}

if(count_digits != 4)

{

cout << "Enterd year "<<year1<<" is wrong"<<endl;

cout<<"Enter correct year"<<endl;

cin>>year;

flag=0;

}

else

flag=1;

}

dYear = year1;

}

main.cpp

#include<iostream>

#include "dateType.h"

using namespace std;

int main()

{

dateType *dt1=new dateType();

cout<<"Date is "<<endl;

dt1->printDate();

cout<<endl;

dt1->isLeapYear();

cout<<endl;

dateType *dt2=new dateType(11,14,2019);

cout<<"Date is "<<endl;

dt2->printDate();

cout<<endl;

dt2->isLeapYear();

cout<<endl;

dt2->setDate(13,32,2016);

cout<<"Date is "<<endl;

dt2->printDate();

cout<<endl;

dt2->isLeapYear();

cout<<endl;

dt1->setDate(10,10,198);

cout<<"Date is "<<endl;

dt1->printDate();

cout<<endl;

dt1->isLeapYear();

cout<<endl;

system("pause");

return 0;

}

You might be interested in
You are asked to provide a list of security groups a user is a member of. You write a script to pull the data from Active Direct
Whitepunk [10]

Answer:

I have no clue. I wish I could help though.

Explanation:

Sorry

7 0
3 years ago
Imagine that you work for a company directly related to your major. Your company is preparing for expansion and your boss, Ms. S
shutvik [7]

Answer:

start with what you know

Explanation:

6 0
2 years ago
write a 2d array c program that can capture marks of 15 students and display the maximum mark, the sum and average​
bekas [8.4K]

Answer:

#include <stdio.h>  

int MaxMark(int* arr, int size) {

   int maxMark = 0;

   if (size > 0) {

       maxMark = arr[0];

   }

   for (int i = 0; i < size; i++) {

       if (arr[i] > maxMark) {

           maxMark = arr[i];

       }

   }

   return maxMark;

}

int SumMarks(int* arr, int size) {

   int sum = 0;

   for (int i = 0; i < size; i++) {

       sum += arr[i];

   }

   return sum;

}

float AvgMark(int* arr, int size) {

   int sum = SumMarks(arr, size);

   return (float)sum / size;

}

int main()

{

   int student0[] = { 7, 5, 6, 9 };

   int student1[] = { 3, 7, 7 };

   int student2[] = { 2, 8, 6, 1, 6 };

   int* marks[] = { student0, student1, student2 };

   int nrMarks[] = { 4, 3, 5 };

   int nrStudents = sizeof(marks) / sizeof(marks[0]);

   for (int student = 0; student < nrStudents; student++) {              

       printf("Student %d: max=%d, sum=%d, avg=%.1f\n",  

           student,

           MaxMark(marks[student], nrMarks[student]),

           SumMarks(marks[student], nrMarks[student]),

           AvgMark(marks[student], nrMarks[student]));

   }

   return 0;

}

Explanation:

Here is an example using a jagged array. Extend it to 15 students yourself. One weak spot is counting the number of marks, you have to keep it in sync with the array size. This is always a problem in C and would better be solved with a more dynamic data structure.

If you need the marks to be float, you can change the types.

3 0
2 years ago
g Assignment 8: Driving costs Driving is expensive. Write a program with a car's miles/gallon and gas dollars/gallon as input, a
zavuch27 [327]

Answer:

miles_gallon = float(input("Enter car's miles/gallon: "))

dollars_gallon = float(input("Enter gas dollars/gallon: "))

print("Gas cost for 20 miles is $", (20 / miles_gallon) * dollars_gallon)

print("Gas cost for 75 miles is $", (75 / miles_gallon) * dollars_gallon)

print("Gas cost for 500 miles is $", (500 / miles_gallon) * dollars_gallon)

Explanation:

*The code is in Python.

Ask the user to enter the car's miles/gallon and gas dollars/gallon

Calculate the gas cost for 20 miles, divide 20 by miles_gallon and multiply the result by dollars_gallon, then print it

Calculate the gas cost for 75 miles, divide 75 by miles_gallon and multiply the result by dollars_gallon, then print it

Calculate the gas cost for 500 miles, divide 500 by miles_gallon and multiply the result by dollars_gallon, then print it

5 0
2 years ago
JAVA
avanturin [10]

Answer:

   public ArrayList onlyBlue(String[] clothes){

       ArrayList<String> blueCloths = new ArrayList<>();

       for(int i =0; i<clothes.length; i++){

           if(clothes[i].equalsIgnoreCase("blue")){

               blueCloths.add(clothes[i]);

           }

       }

       return blueCloths;

   }

Explanation:

  • Create the method to accept an Array object of type String representing colors with a return type of an ArrayList
  • Within the method body, create and initialize an Arraylist
  • Use a for loop to iterate the Array of cloths.
  • Use an if statement within the for loop to check if item equals blue and add to the Arraylist.
  • Finally return the arrayList to the caller
3 0
2 years ago
Other questions:
  • Identify the computer cycle in each of the descriptions below by choosing the answer from the
    12·1 answer
  • How do online note-taking tools support students’ academic goals? Check all that apply.
    9·2 answers
  • What would be a reason for using a workstation rather than a personal computer?
    7·1 answer
  • HELLO!!!! For instance, will we get an error if we put a space after the word “print” and before the opening parenthesis in pyth
    9·1 answer
  • Ethan wants to change the font in his document. He should _____.
    8·1 answer
  • Brenda has created a Microsoft Excel spreadsheet which has 1000's of cells of data. She is looking for specific information in t
    11·1 answer
  • Using C++
    13·1 answer
  • Can able to Computer decide its input by itself? How ?​
    15·1 answer
  • To read encrypted data, the recipient must decipher it into a readable form. What is the term for this process?.
    12·1 answer
  • windows switches to secure desktop mode when the uac prompt appears. what is the objective of secure desktop mode?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!