VUsolutions Transferred to AchiKhasi.com

From December 2011, this blog www.VUsolutions.blogspot.com is transferred to http://achikhasi.com/vu/ . So, you may visit http://achikhasi.com/vu/ for latest study related help.

Back to home VUsolutions

VUsolutions Fans Club [join us for MORE solutions]

VUsolutions on Facebook

CS201- Introduction to Programming Solution

Wednesday, June 24, 2009 Posted In Edit This
Problem Statement:
Write a c++ program which consists of two classes:
1. Date
2. Student
First class Date should contain three data members:
Day
Month
Year
Date also contain following member functions:
Setter function
Getter function
showdate()

Now second class Student should have following three data members:
ST_ID
Name
Ad_date
Where ID and Name are char pointer while Ad_date (Date of Admission) is of type Date.

Student class should contain two member functions:
Display()
setdate()
Now in main function create an object of Class Student and call the member functions with it.
=========================================================
Sample output:

Name: Ali
ID: BC020400000
Admission Date: 12-08-2008

==========================================================


__________________________________________

SOLUTION:

// header file section

#include
#include
using namespace std;

class Date
{
public: int day;
int month;
int year;

public://Constructor
Date()
{
day=0;
month=0;
year=0;
}
//Member function declaration
//Mutator functions
void setDay(int);
void setMonth(int);
void setYear(int);
//Accessor functions
int getDate();
int getMonth();
int getYear();
//show date function
void showDate();
}
//member function definitions

void Date::setDate(int d)
{
//input validation
if (d<1>31)
{
cout<<"Invalid month please reenter it";
cin>>d;
}//end if
day=d;
}//end set day

void Date::setMonth(int m)
{
//input validation
if(m<1>12)
{
cout<<"invalid month please reenter it";
cin>>m;
}//end if
month=m;
}//end set month

void Date::setYear(int y)
{
year=y;
}//end set year

int Date::getDay()
{
return day;
}//end get day

int Date::getMonth()
{
return month;
}//end get month

int Date::getYear()
{
return year;
}//end get year

void Date:: showDate()
{
cout<
}
class Student
{
public:
char *ST_ID;
char *Name;
Date Ad_date;
public:
student()
{
Name=new char[20];
ST_ID=new char[10];
cout<<"Enter name:";
cin.getline(Name,20);
cout<<"Enter ID:";
cin.getline(ST_ID,10);
}
void setdate()
{
cout<<"Enter Day:";
cin>>Ad_date.day;
cout<<"Enter Month:";
cin>>Ad_date.month;
cout<<"Enter Year:";
cin>>Ad_date.year;
}
void Display()
{
cout<<"Name:"<
cout<<"ID:"<
cout<<"Admission Date:";
Ad_date.showDate();
}
};
main()
{
object.setDate();
object.display();
//pause system for a while
system("pause");
}//end main

Back to home VUsolutions

Shaadi.com: Just create ur account & find ur partner or EARN money, its reall & EASY

VUsolutions Followers (Join NOW and Get Extra Benefits)

Install LATEST toolbar having lot of features - GET solutions on Desktop

toolbar powered by Conduit
Caliplus 300x250 NoFlam VitoLiv 468x60 GlucoLo