[SOLVED] CS c++ // From Walter Savitch book resources Absolute C++

$25

File Name: CS_c++_//_From_Walter_Savitch_book_resources__Absolute_C++.zip
File Size: 546.36 KB

5/5 - (1 vote)

// From Walter Savitch book resources Absolute C++

//This is the application file: timedemo.cpp. This program.
//demonstrates hiding the helping functions in an unnamed namespace.

#include
// Here we dont use using namespace std because we use fully qualified names
// below (e.g. DTimeSavitch::DigitalTime).
#include dtime.h

// Declare a free function readHour() in the global scope. If readHour() would not have been defined
// in the unnamed namespace of the dtime.cpp file, it would also have been in the global scope,
// creating a redefinition/name clash. As readHour() was defined in the unnamed namespace in the
// dtime.cpp file, it is only accessible from within the dtime.cpp compilation unit itself,
// and thus the name clash does not occur here.
void readHour(int& theHour);

int main( ){
// Here we use fully qualified names.
// This is why we dont have to use using namespace in the #includes above.
using std::cout;
using std::cin;
using std::endl;
using DTimeSavitch::DigitalTime;

int theHour;
readHour(theHour);
DigitalTime clock(theHour, 0), oldClock;
oldClock = clock;
clock.advance(15);
if (clock == oldClock)
cout << “Something is wrong.”;cout << “You entered ” << oldClock << endl;cout << “15 minutes later the time will be ” << clock << endl;clock.advance(2, 15);cout << “2 hours and 15 minutes after that
” << “the time will be ” << clock << endl;return 0;}// Definition of the readHour() free function declared above.void readHour(int& theHour){using std::cout;using std::cin; cout << “Let’s play a time game.
” << “Let’s pretend the hour has just changed.
” << “You may write midnight as either 0 or 24,
” << “but, I will always write it as 0.
” << “Enter the hour as a number (0 to 24): “;cin >> theHour;
}

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] CS c++ // From Walter Savitch book resources Absolute C++
$25