We are here with you hands in hands to facilitate your learning & don't appreciate the idea of copying or replicating solutions. Read More>>

Looking For Something at vustudents.ning.com? Click Here to Search

www.bit.ly/vucodes

+ Link For Assignments, GDBs & Online Quizzes Solution

www.bit.ly/papersvu

+ Link For Past Papers, Solved MCQs, Short Notes & More

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

 

 

 

 

 

+ How to Follow the New Added Discussions at Your Mail Address?

+ How to Join Subject Study Groups & Get Helping Material?

+ How to become Top Reputation, Angels, Intellectual, Featured Members & Moderators?

+ VU Students Reserves The Right to Delete Your Profile, If?


See Your Saved Posts Timeline

Views: 6236

.

+ http://bit.ly/vucodes (Link for Assignments, GDBs & Online Quizzes Solution)

+ http://bit.ly/papersvu (Link for Past Papers, Solved MCQs, Short Notes & More)

+ Click Here to Search (Looking For something at vustudents.ning.com?)

+ Click Here To Join (Our facebook study Group)

Attachments:

Replies to This Discussion

Graded ha ya ?

KOI To Solve Karo 

Please Discuss here about this assignment.Thanks

Our main purpose here discussion not just Solution

We are here with you hands in hands to facilitate your learning and do not appreciate the idea of copying or replicating solutions.

Chaudhary.cpp

So enjoy friends.

by Chaudhary from Pakpattan M NAD36M-CH

#include <iostream>
// i have an other idea to solve this assignment in method if-else
using namespace std;
class Time {
public:
Time(); // default constructor
void setTime(int,int,int);
void printMilitary();
void printStandard();
private:
int hour;
int minute;
int second;
};
Time::Time() { hour = minute = second = 0; }

// Solved by M NAD36M-CHAUDHARY FROM PAKPATTAN
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;
}
// Print time in standard format
void Time::printStandard()
{
cout ((hour == 0 || hour == 12) ? 12 : hour % 12) ;
cout ":" (minute < 10 ? "0" : "") minute ;
cout ":" (second < 10 ? "0" : "") second ;
cout (hour < 12 ? " AM" : " PM");
}
// Print Time in military format
void Time::printMilitary()
{
cout (hour < 10 ? "0" : "") hour ":" ;
cout (minute < 10 ? "0" : "") minute ":" ;
cout (second < 10 ? "0" : "") second;
}

//main simple class Time
int main()
{
cout" \t\t******Solved by M NAD36M-CHAUDHARY FROM PAKPATTAN****** \n";
Time t; // instantiate object t of class Time

cout "The initial standard time is ";
t.printStandard();
cout "\nThe initial military time is ";
t.printMilitary();
// Solved by M NAD36M-CHAUDHARY FROM PAKPATTAN
t.setTime(13, 27, 6);
cout "\n\nstandard time after setTime is ";
t.printStandard();
cout "\nmilitary time after setTime is ";
t.printMilitary();
t.setTime(99, 99, 99);
// attempt invalid values who above than in hour 24, in minute 60 and in second 60.
cout "\n\nAfter attempting invalid settings:\n" ;
cout "\nStandard time: ";
t.printStandard();
cout "\nMilitary time: ";
t.printMilitary();
// Solved by M NAD36M-CHAUDHARY FROM PAKPATTAN
cout endl;
system("pause");
}

friends dont wory its easy start discussion !

WOW!

Very easy assignments, students should have to hear the lectures and follow the handouts, after that download the instructions from your LMS download section and follow the instructions. I hope you will be able to solve your assignments. If you still have any query please post here, I will try to solve your queries.

To install software you can ask for me Teamviewer session.

Note: Do not copy past any material from here, just get idea from here and implement it. Other wise you will get zero marks.

Thanks!

#include <iostream>

using name space std;

class Time 

{

private :int hour;

int minute;

int seconds;

publice:

void setTime(int, int, int);

void show12Hour();

void show24Hour();

};

here is the idea and algo to solve the problem,, please read and study and understand as much as you can,, copying without learning is wastage of time,,, enjoyyy

Attachments:

 Zeeshan  thanks for sharing...gud keep it up 

#include<iostream>
using namespace std;

class Time
{
public:
Time()
{
hour = 00;
minute = 00;
seconds = 00;
}
void setTime(int h, int m, int s)
{
hour = h;
minute = m;
seconds = s;
}
void show12Hour()
{
int h, m, s;
h = hour;
m = minute;
s = seconds;
if(h>12 && h<24 && m>=00 && m<60 && s>=00 && s<60)
{
h -= 12;
couth":"m":"s" PM"endl;
}
else if (h>12 && h<24 && m >59 && s >= 00 && s < 60)
{
h -= 12;
m = 00;
couth":"m":"s" PM"endl;
}
else if (h >12 && h < 24 && m >=00 && m <60 && s >59)
{
h -= 12;
s =00;
couth":"m":"s" PM"endl;
}
else if (h >12 && h < 24 && m >59 && s >59)
{
h -= 12;
s =00;
m =00;
couth":"m":"s" PM"endl;
}
else if (h>=01 && h<=12 && m>=00 && m <60 && s >=00 && s<60)
{
couth":"m":"s" AM"endl;
}
else if (h >= 01 && h <= 12 && m >59 && s >= 00 && s < 60)
{
m =00;
couth":"m":"s" AM"endl;
}
else if (h >= 01 && h <= 12 && m >=00 && m <60 && s >59)
{
s =00;
couth":"m":"s" AM"endl;
}
else if (h >= 01 && h <= 12 && m >59 && s >59)
{
m=00;
s=00;
couth":"m":"s" AM"endl;
}
else if ((h <= 0 || h > 24) && m >59 && s >59)
{
h = 12;
m =00;
s = 00;
couth":"m":"s" AM"endl;
}
else if ((h <= 0 || h > 24) && m <60 && s >59)
{
h = 12;
s = 00;
couth":"m":"s" AM"endl;
}
else if ((h <= 0 || h > 24) && m >59 && s<60)
{
h = 12;
m = 00;
couth":"m":"s" AM"endl;
}
else if ((h <= 0 || h > 24) && m >59 && s>59)
{
h = 12;
m = 00;
s = 00;
couth":"m":"s" AM"endl;
}
else if (h <= 0 && m <=0 && s <= 0)
{
h = 12;
m =00;
s = 00;
couth":"m":"s" AM"endl;
}
}
void show24Hour()
{
int h, m;
h = hour;
m = minute;

if(h > 24)
{
h = 00;
}
if(m > 59)
{
m = 00;
}
if (h < 01 && m < 01 )
{
h = 00;
m = 00;
}
couth":"mendl;
}

private:
int hour;
int minute;
int seconds;
};


int main()
{
Time t;
cout"Initial Time"endl;
cout"Time display in 12 hours format: ";
t.show12Hour();
cout"Time display in 24 hours format: ";
t.show24Hour();

t.setTime(13,55,23);
cout"Time display in 12 hours format: ";
t.show12Hour();
cout"Time display in 24 hours format: ";
t.show24Hour();

t.setTime(23,78,63);
cout"Time display in 12 hours format: ";
t.show12Hour();
cout"Time display in 24 hours format: ";
t.show24Hour();

t.setTime(25,67,98);
cout"Time display in 12 hours format: ";
t.show12Hour();
cout"Time display in 24 hours format: ";
t.show24Hour();
}

#include <iostream>
using namespace std;
class Time
{
private:
int hour;
int minute;
int seconds;
public:
Time()
{
hour = 0;
minute = 0;
seconds = 0;
}
void setTime(int h, int m, int s)
{
if ( (h > 0 && h <= 24) &&
(m > 0 && m <= 60) &&
(s > 0 && s <= 60) )
{
hour = h;
minute = m;
seconds = s;
}
else
{
hour = 0;
minute = 0;
seconds = 0;
}
}
void show12Hour()
{
int hours = hour;
string unit = "";
if (hours > 12)
{
unit = " PM";
}
else if (hours <= 12 && hours > 0)
{
unit = " AM";
}
if (hours > 12)
{
hours = hours - 12;
}
cout "Time display in 12 hours format: " hours ":"
minute ":" seconds unit endl;
}
void show24Hour()
{
cout "Time display in 24 hours format: " hour ":"
minute ":" seconds endl;
}
};
int main()
{
Time t;
cout "Initial time" endl;
t.show12Hour();
t.show24Hour();
t.setTime(13,55,23);
cout "After set" endl;
t.show12Hour();
t.show24Hour();
t.setTime(25,67,98);
cout "After setting invalid values" endl;
t.show12Hour();
t.show24Hour();
cin.get();
}

RSS

Latest Activity

Areeha Chuhdary updated their profile
4 minutes ago
Zimal updated their profile
5 minutes ago
IBS and Ahmer Rajpoot are now friends
6 minutes ago
Muhammad Hanan Sarfraz liked + M.Tariq Malik's discussion ENG301 Business Communication Assignment No 01 Fall 2019 Solution & Discussion
34 minutes ago
+ M.Tariq Malik replied to Ahmer Rajpoot's discussion MCM101Assignment No 01 Fall 2019 Solution & Discussion
38 minutes ago
+ M.Tariq Malik replied to + M.Tariq Malik's discussion MCM301 Communication skills Assignment No 01 Fall 2019 Solution & Discussion in the group MCM301 Communication skills
38 minutes ago
+ M.Tariq Malik liked Ahmer Rajpoot's discussion MCM101Assignment No 01 Fall 2019 Solution & Discussion
46 minutes ago
Ahmer Rajpoot posted a discussion
1 hour ago
+ M.Tariq Malik liked + !♛EMAN FATIMA!'s discussion project (Numerical Solution of Differential Equation by using Predictor Corrector Method )
1 hour ago
m.tahir joined + M.Tariq Malik's group
1 hour ago
MUDASAR SHAKIL liked ♦_"Tooba"_♦'s photo
1 hour ago
MUDASAR SHAKIL liked jiya's profile
1 hour ago
Ikra butt posted a status
1 hour ago
Ikra butt posted a status
"https://www.youtube.com/channel/UCVnIaKstaSmXBwF5-8rTGTw Its YOUTUBE CHANNEL for all solution GDB, ASSIGNMENTS, QUIZZ"
1 hour ago
+ !♛EMAN FATIMA! joined + M.Tariq Malik's group
1 hour ago
Shakir Siddiqui posted a status
"Design of FANETs as an Application of Remote Virtual Health Assistant"
1 hour ago
Ikra butt joined + M.Tariq Malik's group
2 hours ago
ϝ ι ყ α liked + ! ! ! ! ! ! ! ! ! ! ! ! ! ! !'s discussion Hamesha sath rehne ki aadat kuch nahin hoti
2 hours ago
+ Iuuoɔǝut + posted discussions
2 hours ago
+ ! ! ! ! ! ! ! ! ! AG replied to + "J ɨ y ą ⋆'s discussion Mohabat
2 hours ago

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

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