Computers & Internet Logo

Related Topics:

Posted on Mar 26, 2009

Create a class called Date in C++

Create a class called Date that includes three pieces of information as data members- a month(type int), a day(type int) and a year(type int). The class should have a constructor with 3 parameters to initialize the 3 data members. Assume that valuesprovided for year and day are correct but ensure that the month value is in the range 1-12 if not set the month to 1. provide a set and get function for each member. provide a member function displayDate that displays the month, day and year separated by (/) slashes. write a test program that demonstrates calss Date's capabilities.













1 Answer

Anonymous

Level 1:

An expert who has achieved level 1.

Hot-Shot:

An expert who has answered 20 questions.

Corporal:

An expert that has over 10 points.

Mayor:

An expert whose answer got voted for 2 times.

  • Contributor 32 Answers
  • Posted on Oct 12, 2009
Anonymous
Contributor
Level 1:

An expert who has achieved level 1.

Hot-Shot:

An expert who has answered 20 questions.

Corporal:

An expert that has over 10 points.

Mayor:

An expert whose answer got voted for 2 times.

Joined: Oct 12, 2009
Answers
32
Questions
0
Helped
17440
Points
88

I wrote it for you:
date.cpp
date.h
Remember, this is only a demonstration, so you can learn from it!

Add Your Answer

×

Uploading: 0%

my-video-file.mp4

Complete. Click "Add" to insert your video. Add

×

Loading...
Loading...

Related Questions:

1helpful
1answer

Create a class called date and a child called time in c++

Where to begin?
Easy: FIND SUITABLE LIBRARY
answer is easy, but finding is hard enough.
Hopefully c++ standart has time.h that has functions you need.
Without any talking source code below:
I created 2 files: data.h which has classes and functions and main.cpp :)

-----------------data.h-----------------
#ifndef _DATA_H_
#define _DATA_H_

#include <time.h>

class Data
{
public:
time_t rawtime; // time.h requres this
struct tm *timeinfo; // and this also
public:
Data(); // constructor
int getMonth();
int getDay();
int getYear();
char *getAll();
};


class Time : public Data // child funqcion
{
public:
int getH();
int getM();
int getS();
};

Data::Data() // copy of constructor
{
time(&rawtime);
timeinfo = localtime(&rawtime);
}

int Data::getMonth()
{

return timeinfo->tm_mon;
}

int Data::getDay()
{
return timeinfo->tm_wday;
}

int Data::getYear()
{
return timeinfo->tm_year;
}

char *Data::getAll()
{
return asctime(timeinfo);
}

int Time::getH()
{
return timeinfo->tm_hour;
}

int Time::getM()
{
return timeinfo->tm_min;
}

int Time::getS()
{
return timeinfo->tm_sec;
}

#endif
----------------------END OF FILE--------------------
I hope you know include file rule when working with multiple files. I mean you understand #ifndef and #define...

and the main.cpp:

#include "data.h"
#include <iostream>

//I hope you understand all this...

using namespace std;

Data myData;
Time myTime;
const char *months[12] =
{
"January",
"Febryary",
"March",
"April",
"May",
"June",
"Jule",
"August",
"September",
"October",
"November",
"December",
};

const char *days[7] =
{
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
};

int gmonth;
int gday;
int gyear;
int ghour;
int gmin;
int gsec;
char *compact; // why char *compact and not char compact? because Data.getAll returns *char

int main(int argc, char *argv[])
{
cout << "Getting month...\n";
gmonth = myData.getMonth();
cout << "Current month: " << months[gmonth];
cout << endl;
cout << "Getting week day...\n";
gday = myData.getDay();
cout << "Current week day: " << days[gday];
cout << endl;
cout << "Getting year...\n";
gyear = myData.getYear() + 1900; // +1900 is necessary :) because year is calculating after 1900
cout << "Current year: " << gyear;
cout << endl;
cout << "Getting hour...\n";
ghour = myTime.getH();
cout << "Current hour: " << ghour;
cout << endl;
cout << "Getting minutes...\n";
gmin = myTime.getM();
cout << "Current minutes: " << gmin;
cout << endl;
cout << "Getting seconds...\n";
gsec = myTime.getS();
cout << "Current seconds: " << gsec;
cout << endl;
cout << endl;
compact = myData.getAll(); // Coolest one :)
cout << compact << endl;
system("PAUSE");
return EXIT_SUCCESS;
}
----------------END OF FILE--------------------
I clearly don't understand what set hours, minutes, secs mean:'
Tested and working.
If you have any questions write comment.
I compiled this project in DevCpp, but it will work for Visual Studio too.
This might be different what you expected but solve any problem AS EASY AS POSSIBLE in programming. Solve problem i mean everything is working.

Aah, I've written a lot :)
Please rate my solution...
And Successful Programming!
0helpful
1answer

Hello... i need a program in c...... a calendar where you can save on a specific date a reminder...

#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <iostream.h>
#include <fstream.h>


int getdaycode(int year)
{
return(year+(year-1)/4-(year-1)/100+(year-1)/400)%7;
}

int bool getleapcode(int year)
{
return year%4==0&&year%100!=0''year%400==0;
}


main()
{
clrscr();
int choice,month,days,day,daycode;
printf("\t\t\tSCHEDULER-CALENDAR PROGRAM\n\n\n");
printf("Please choosefrom the Menu:\n");
printf("\t1- Calendar Dislplay\n");
printf("\t2- Schedule Editor\n");
printf("\nChoice: ");
scanf("%d",&choice);

if(choice==1)
{
clrscr();
int year;
printf("\tCalendar Display\n\n");
printf("Type the YEAR to be Displayed: ");
scanf("%d",&year);
printf("\nYear = %d",year);

bool leapcode;

daycode=getdaycode(year);
leapcode=getleapcode(year);


for(month=1;month<=12;month++)
{
switch(month)
{
case 1:
{
printf("\nJanuary");
days=31;
}
break;

case 2:
{
printf("\n\nFebruary");
if(leapcode)
{
days=29;
}
else
{
days=28;
}
}
break;

case 3:
{
printf("\n\nMarch");
days=31;
}
break;

case 4:
{
printf("\n\nApril");
days=30;
}
break;

case 5:
{
printf("\n\nMay");
days=31;
}
break;

case 6:
{
printf("\n\nJune");
days=30;
}
break;

case 7:
{
printf("\n\nJuly");
days=31;
}
break;

case 8:
{
printf("\n\nAugust");
days=30;
}
break;

case 9:
{
printf("\n\nSeptember");
days=31;
}
break;

case 10:
{
printf("\n\nOctober");
days=30;
}
break;

case 11:
{
printf("\n\nNovember");
days=31;
}
break;

case 12:
{
printf("\n\nDecember");
days=30;
}
break;
}


printf("\n\nSun Mon Tue Wed Thu Fri Sat\n");

for(day=1;day<=daycode*5;day++)
{
printf(" ");
}
for(day=1;day<=days;day++)
{
printf(" %d ",day);

if((day+daycode)%7>0)
{
printf(" ");
}
daycode=(daycode+days)%7;
}

}



}
if(choice==2)
{
printf("Schedule Editor\n\n");
FILE *fptr1;
char filename1[]="sched.txt";
int reval=SUCCESS;

if((fptr1==fopen(filename1,"w"))
{
printf("File cannot be opened\n");
reval=FAIL;
}
else
{
CharReadWrite(fptr1);
fclose(fptr1);
}


int

getch();
return 0;
}
0helpful
1answer

In c create a class called car having members model no,year,no of doorsand mileage and have member functions to add and modify the members of the car

create a class called date that includes three pieces of information as data members-a month (type int), a day (type int) and a year (type int) in c++
1helpful
1answer

C++

This is a homework problem. You should not expect folks to answer this. There are multiple questions here, as you know.

If you want to do it, you first need to do is start at the sentence, "Create a class ACCOUNT..."

So, "How do you do create a class?" would be one question.

Answer: It is done with an editor creating two new files, one the file ACCOUNT.h (where the class is declared) and two the file ACCOUNT.cpp (where the class member/functions are defined).

All these answers are in your text book.

THEN, work on the next part, "... that stores customerName, accountNumber, etc."

Do it one part at a time and you can program. The next part is to create two new classes, CUR_ACCT and SAV_ACCT. Like the first one, these will go in their own file, like CUR_ACCT.h and CURR_ACCT.cpp.

Take it slow and do one piece at a time.

Only this way can you learn.

0helpful
1answer

Give me an example about defined data types

data types are variables which is used to store values in to the memory for ex: numbers can be stored in the for of integers(int), alphabets and special characters can be storerd as characters(char), date can be stored as date format(date) etc.,

these are called data types:
int
char
date
varchar
0helpful
1answer

Create an employee class contains following members data members:

class employee
{
int emp_no;
char emp_name[80];
float Basic;
public:
employee(int no, char *name, float basic)
{
emp_no=no;
emp_name=name;
Basic=basic;
}

float int calc_da()
{
return(Basic*52/100);
}

float calc_it()
{
return((Basic+calc_da())*30/100);
}

float calc_netSal()
{return(Basic+calc_da()-calc_it();}
};
8helpful
2answers

Can I get the asswer for the below questions

A book shop maintains the inventory of books that are being sold at the shop. The list has details like author, title, price, publisher and stock position. Whenever a customer wants a book, the sales person inputs the title and author and the system searches the list and displays a suitable message if it is not available. If it is available, the system displays the book details and requests for the number of copies required. If the copies are available, the total cost of the copies requested is displayed, otherwise the message ‘copies not in stock’ is displayed.
Design a system using a class called BOOKS with suitable member functions and constructors. Use new operator in constructors to allocate required memory space.
0helpful
3answers

I need solve this type calulation is 0,1,1,2,3,5,8,13,21,34 etc. u send me the code of this type of calculation in c++ language

Ok! Here's a snippit from some code I wrote in beginning c++ classes. However, don't just cut and paste it. Know how it works since it's important in algorithm examination!

Just tested it, compiles and runs perfectly on GCC 4.0.1 on my mac, as well as my linux boxen. Windows may take some changes to output data.

/***********************************************
* Steven Parker
* Calculating Fib Sequence
* after two starting values, each number is the
* sum of the two preceding numbers
***********************************************/
#include <iostream>
using namespace std;

int main() {
int whentostop = 20; //How many values of sequence to calculate
int fib[whentostop]; //Hold fib numbers

for (int i=0; i < whentostop; i++) {
if (i == 0)
fib[0] = 0;
else if (i == 1)
fib[1] = 1;
else
fib[i] = fib[i-1] + fib[i-2];

cout << "Fibonacci[" << i << "]: " << fib[i] << endl;
}
return 0;
}
0helpful
1answer

Schema classes and attributes

Every directory object you create is an instance of an object class contained in the schema. Each object class contains a list of associated attributes that determine the information the object can contain. Classes and attributes are defined independently, so that a single attribute can be associated with multiple classes. All schema classes and attributes are defined by the classSchema and attributeSchema objects, respectively.

Classes

ClassSchema objects are used to define classes in the schema. A classSchema object provides the template for building directory objects of that class. Examples of classSchema include User and Server. A classSchema object contains, among other things, the following information:
Class type (structural, abstract, or auxiliary)

Common name and Lightweight Directory Access Protocol (LDAP) display name

Lists of the "must contain" and "may contain" attributes for instances of the object

Relative distinguished name attribute

A list of possible parent classes

Class types

Three different types of classes exist in the schema:Class type Purpose

Structural
Used to instantiate objects (users, servers and so on) in the directory.

Abstract
Provides templates for deriving structural classes

Auxiliary
Contains predefined lists of attributes that can be included in structural and abstract classes

Attributes

AttributeSchema objects are used to define attributes in the schema. An attributeSchema object determines the allowable contents and syntax for instances of that attribute in the directory. Examples of attributeSchema include User-Principal-Name and Telex-Number. An attributeSchema object contains, among other things, the following information:•
Common name and LDAP display name

Syntax rules

Data constraints (single versus multivalued, minimum, and maximum values)

Whether and how the attribute is indexed
Not finding what you are looking for?

1,416 views

Ask a Question

Usually answered in minutes!

Top Computers & Internet Experts

Grand Canyon Tech
Grand Canyon Tech

Level 3 Expert

3867 Answers

Brad Brown

Level 3 Expert

19187 Answers

Cindy Wells

Level 3 Expert

6688 Answers

Are you a Computer and Internet Expert? Answer questions, earn points and help others

Answer questions

Manuals & User Guides

Loading...