473,387 Members | 1,534 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

classes

17
Hi...ive having some prob dealing wiv classes question though ive understood the concept.. if u cud help me wiv the following question:

The class Date has the following data members:
 Month
 Day
 Year
and member functions:
 A default constructor that initialises all data members to zero.
 A constructor to create and initialise a Date object with the values passed as parameters
 Assigndate to assign values to the data members from the keyboard in the format:
Day: 9
Month: 10
Year: 2002
 Displayshort to display a date in short form e.g. “09/10/2002”
 DisplayVerbose to display a date in form “October 9, 2002”
 NextDay to change the date to next day e.g. “October 10, 2002”

(a) Write the class interface for the class Date.

(b) Write the full function implementation for the member functions of the class Date.

(c) Write a main program that declares two objects D1 and D2 of type Date. D1 must be initialised to the value “23 October 2002” and D2 must get its value from the keyboard. The program must then find the earlier of D1 and D2 and display the same in both formats. The program must also set the date D2 to next day and display the same in both formats.



ive started by doin the 3rd part c directly but dunno how to continue and if wat ive done is correct..this is wat ive manage to do uptil nw:


Expand|Select|Wrap|Line Numbers
  1. #include<iostream.h>
  2. #include<conio.h>
  3.  
  4.   class Date{
  5.     char month[10];
  6.     int month;
  7.     int day;
  8.     int year;
  9.  
  10.   public:
  11.     Date();
  12.     Date(char, int, int);
  13.     void Assigndate();
  14.     void Displayshort();
  15.     void DisplayVerbose();
  16.     void NextDay();
  17.     }
  18.  
  19. Date::Date()
  20. { month=0;
  21.   day=0;
  22.   year=0;
  23. }
  24.  
  25. void Assigndate()
  26. { cin>>day;
  27.   cout<<"Day: "<<day<<endl;
  28.   cin>>month;
  29.   cout<<"Month: "<<month<<endl;
  30.   cin>>year;
  31.   cout<<"Year: "<<year<<endl;
  32. }
  33.  
  34. void Displayshort()
  35. { cout<<day<<"/"<<month<<"/"<<year<<endl;
  36. }
  37.  
  38. void NextDay()
  39. { D1.date(char, int, int)
  40.  d++;
  41.  cout<<D1;
  42. }
  43.  
  44.  
  45. void main(){
  46. Date D1,D2;
  47.  
  48. cout<<"Enter the date"<<endl;
  49. cin>>date;


ive not completed it..hw do i display the date in different formats..plz correct it n how do i continue
Feb 16 '07 #1
1 1195
Ganon11
3,652 Expert 2GB
For the different formats...

When you get the month variable either from the constructor or from the Assigndates function, you can use a set of if...else statements to determine the name of the month. If the month entered is 1, then the name is January, and you can store this in your char array. If the month entered is 2, then the month is February, and so on.

When you get to the DisplayVerbose function, you can display the month name, followed by a space, followed by the day, followed by a comma and a space, then the year.
Feb 16 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Bob Rock | last post by:
Hello, in the last few days I've made my first few attempts at creating mixed C++ managed-unmanaged assemblies and looking aftwerwards with ILDASM at what is visible in those assemblies from a...
9
by: Jack | last post by:
Hello I have a library of calculationally intensive classes that is used both by a GUI based authoring application and by a simpler non-interactive rendering application. Both of these...
9
by: Aguilar, James | last post by:
I know that one can define an essentially unlimited number of classes in a file. And one can declare just as many in a header file. However, the question I have is, should I? Suppose that, to...
12
by: Langy | last post by:
Hello I'm fairly new to C++ but have programmed several other languages and found most of c++ fairly easy (so far!). I've come to a tutorial on classes, could someone please tell me why you...
4
by: john townsley | last post by:
do people prefer to design classes for the particular job or for a rangle of tasks they might encounter now and in the future. i am doing some simple win32 apps and picking classes is simple, but...
2
by: joye | last post by:
Hello, My question is how to use C# to call the existing libraries containing unmanaged C++ classes directly, but not use C# or managed C++ wrappers unmanaged C++ classes? Does anyone know how...
18
by: Edward Diener | last post by:
Is the packing alignment of __nogc classes stored as part of the assembly ? I think it must as the compiler, when referencing the assembly, could not know how the original data is packed otherwise....
6
by: ivan.leben | last post by:
I want to write a Mesh class using half-edges. This class uses three other classes: Vertex, HalfEdge and Face. These classes should be linked properly in the process of building up the mesh by...
0
by: ivan.leben | last post by:
I am writing this in a new thread to alert that I found a solution to the problem mentioned here: http://groups.google.com/group/comp.lang.c++/browse_thread/thread/7970afaa089fd5b8 and to avoid...
2
by: Amu | last post by:
i have a dll ( template class) ready which is written in VC++6. But presently i need to inherit its classes into my new C#.net project.so if there is some better solution with u then please give me...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.