Latest Activity In Study Groups

Join Your Study Groups

VU Past Papers, MCQs and More

We non-commercial site working hard since 2009 to facilitate learning Read More. We can't keep up without your support. Donate.

Uploading instructions

 

  • For clarity and simplicity, you are required to Upload/Submit only one .CPP file

Objective

The objective of this assignment is:

 

  • To give you the idea of practical implementation of class with attributes and functions

 

For any query about the assignment, contact at CS304@vu.edu.pk

 

GOOD LUCK

Problem Statement:

 

Consider the following attributes and functions of the class Time:

Attributes:

  • int hour
  • int minute
  • int seconds

Functions:

  • void setTime(int, int, int);
  • void show12Hour();
  • void show24Hour();

 

Write a program to instantiate the object of a class Time from the main() function and constructor is called of the class Time automatically to initialize the private data members of the class with 0. Time is printed on the screen in 12 hours format and 24 hours format as follows:

 

Initial Time:

 

Time display in 12 hours format: 12:00:00 AM

Time display in 24 hours format:  00:00

 

After that use the setTime() function to set the time  by passing the 3 attributes of time i.e setTime(13,55,23) and show the time again after setting:

 

After set:

 

Time display in 12 hours format: 01:55:23 PM

Time display in 24 hours format: 13:55

 

Now try to use setTime() function for setting invalid values i.e setTime(25,67,98) . Your program should not set invalid values of time and show finally the time as initial.

 

Time display in 12 hours format: 12:00:00 AM

Time display in 24 hours format: 00:00

 

 

 

 

 

Views: 6379

Attachments:

Replies to This Discussion

share your error..

source file not find

source file not compile

if u have win 7, use  devcpp-4.9.9.2_setup.exe .

in case of win 8, use http://sourceforge.net/projects/orwelldevcpp/ .

solution ,,,,

Attachments:

#include <iostream>
using namespace std;
class Time {
public:
Time(); // default constructor
void setTime(int,int,int);
void show24hour();
void show12hour();
private:
int hour;
int minute;
int second;
};
Time::Time()
{ hour = minute = second = 0; }


void Time::setTime(int h,int m,int s)
{
hour = (h >= 0 && h < 24) ? h : 0;
minute = (m >= 0 && m < 60) ? m : 0;
second = (s >= 0 && s < 60) ? s : 0;
}
// show time in 12 hour format
void Time::show12hour()
{
cout ((hour == 0 || hour == 12) ?12 : hour % 12) ;
cout ":" (minute < 10 ? "0" : "") minute ;
cout ":" (second < 10 ? "0" : "") second ;
cout (hour < 12 ? " AM" : " PM");
}
// show time in 24 hour format
void Time::show24hour()
{
cout (hour < 10 ? "0" : "") hour ":" ;
cout (minute < 10 ? "0" : "") minute ;
system("pause");
}


//main simple class Time
int main()
{

Time t; // instantiate object t of class Time
cout "initial time " endl;
cout "Time display in 12 hours format: ";
t.show12hour();
cout "\nTime display in 24 hours format: ";
t.show24hour();

t.setTime(13,55,23);
cout "\nAfter set: ";
cout "\nTime display in 12 hours format: ";
t.show12hour();
cout "\nTime display in 24 hours format: ";
t.show24hour();
t.setTime(25,67,98);

system("pause");
cout "\nAfter Setting invalid Values\n" ;

t.show12hour();
cout "\n" ;
t.show24hour();

cout endl;
return 0 ;
system("pause");

}

Sahrish MCS 2nd complete ni hy 

how???

kisi k pass full correct solution hai?

full discussion read kro bro

full correct solution mil jai ga

run kr k check kro 

RSS

Looking For Something? Search Below

Top Trends 

VIP Member Badge & Others

How to Get This Badge at Your Profile DP

------------------------------------

Management: Admins ::: Moderators

Other Awards Badges List Moderators Group

© 2021   Created by + M.Tariq Malik.   Powered by

Promote Us  |  Report an Issue  |  Privacy Policy  |  Terms of Service