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: 6388

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

Latest Activity

ai con replied to + M.Tariq Malik's discussion CS101 Introduction to Computing Assignment No.01 Fall 2021 Solution / Discussion in the group CS101 Introduction to Computing
23 minutes ago
Profile Iconai con and Batool joined + M.Tariq Malik's group
24 minutes ago
ai con replied to + M.Tariq Malik's discussion CS401 Computer Architecture and Assembly Language Programming Final Term Papers Mega Files - Solved MCQs, Short Notes, Solved Past Papers & More in the group CS401 Computer Architecture and Assembly Language Programming
25 minutes ago
ai con replied to + M.Tariq Malik's discussion CS401 Computer Architecture and Assembly Language Programming Final Term Papers Mega Files - Solved MCQs, Short Notes, Solved Past Papers & More in the group CS401 Computer Architecture and Assembly Language Programming
26 minutes ago
ai con replied to + M.Tariq Malik's discussion CS401 Computer Architecture and Assembly Language Programming Final Term Papers Mega Files - Solved MCQs, Short Notes, Solved Past Papers & More in the group CS401 Computer Architecture and Assembly Language Programming
26 minutes ago
ai con replied to + M.Tariq Malik's discussion CS401 Computer Architecture and Assembly Language Programming Final Term Papers Mega Files - Solved MCQs, Short Notes, Solved Past Papers & More in the group CS401 Computer Architecture and Assembly Language Programming
27 minutes ago
ai con joined + M.Tariq Malik's group
27 minutes ago
ai con replied to alvia khan's discussion Attention! All last year students and Recent Graduates! (FELLOWSHIP OPPORTUNITY)
28 minutes ago

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

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