Menu

Friday, 28 November 2014

Chapter 5,Problem 10:Object Oriented Programming by Robert Lafore in C++ Solution Manual

//27-11-2014
//Ahmad Furqan Attari
//p5.10
#include <iostream>
#include <conio.h>
using namespace std;
int times = 0;
void g_fun(void)
{
times++;
cout << "I have been called " << times << " times." << endl;
}
void s_fun(void)
{
static int stimes = 0;
stimes++;
cout << "I have been called " << stimes << " times." << endl;
}
void main(void)
{
cout << "Global variable version!" << endl;
for (int i = 0; i < 10; i++)
{
g_fun();
}
cout << "Static variable version!" << endl;
for (int j = 0; j < 10; j++)
{
s_fun();
}
_getch();
}

No comments:

Post a Comment