• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 2 out of 8 pages
Exam (elaborations)

CSCI 240 Practice Test Questions with Verified Correct Answers

Document preview thumbnail
Preview 2 out of 8 pages

CSCI 240 Practice Test Questions with Verified Correct Answers

Content preview

CSCI 240 Practice Test Questions with Verified
Correct Answers
Write the constructor for the Time class. It takes three integer arguments: the potential

hour, minute, and second values for the Time object. The constructor should pass the

individual arguments to the setHour, setMinute, and setSecond methods to initialize the

data members.

Time :: Time ( int newHr, int newMin, int newSec )

{

setHour ( newHr );

setMinute ( newHr );

setSecond( newSec );

}

Write the setHour method for the Time class. It takes an integer argument that will

potentially be used to initialize the hour data member. If the passed in value is not

between 1 and 12, inclusive, then initialize the hour data member to 12. Otherwise, use

the passed in value to initialize the hour data member.

void Time :: setHour( int diffHr )

{

if (diffHr < 1 or diffHr > 12)

{

hour = 12;

}

else

{

, hour = diffHr;

}

}

Write the getSecond method for the Time class. It takes no arguments and returns an

integer. This method should simply return the contents of the second data member.

int Time :: getSecond()

{

return second;

}

Write the printTime method for the Time class. It takes no arguments and returns

nothing. This method should print the time in the format hour:minute:second. For

minutes and seconds, if the value is less than 10, display a leading 0.

void Time :: printTime()

{

cout << hour << ":";



if ( minute < 10 )

cout << "0";



cout << minute << ":";

if ( second < 10 )

cout << "0";

Document information

Uploaded on
August 26, 2026
Number of pages
8
Written in
2026/2027
Type
Exam (elaborations)
Contains
Questions & answers
$11.99

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
KenAli
2.6
(18)
Sold
114
Followers
5
Items
23937
Last sold
6 days ago



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions