Site hosted by Angelfire.com: Build your free website today!

APPLICATIONS OF C++ IN THE REAL WORLD

Well, there must be some way for C++ to benefit mankind, or else there'd be no point in it existing.

This program prints a calender, complete with comments and everything:

// THIS PROGRAM PRINTS A CALENDER IN A SEPERATE OUTPUT FILE //
#include // need this for input/output and setw function
#include // for month variables
#include
#include // for output file
// Charles Sabo // name of the genious that made this program
// 11/28/01
// 3rd Period
void month(apstring, int); // function that displays the calender for each month
int day, count; // global variables to be used in both functions
ofstream calender; // output file that displays the calender
int main()
{
int year; // the year the calender is for
cout << "Enter the year this calender is for: ";
cin >> year;
cout << "Enter the day of the week that the year starts on (0 = Sunday, 1 = Monday, " << "2 = Tuesday, 3 = Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday: ";
cin >> day; // user enters the starting day for the year
count = day * 2; // sets the counter to the value of the day variable. I have my reasons.
calender.open("calender.dat"); // open calender file
calender << year << endl; // first display the year
month("January", 31); // passes each month's name and number of days to the function
if (year % 4 != 0) // tests for leap years
month("February", 28);
else if (year % 400 == 0)
month("February", 29);
else if (year % 100 == 0)
month("February", 28);
else
month("February", 29);
month("March", 31);
month("April", 30);
month("May", 31);
month("June", 30);
month("July", 31);
month("August", 31);
month("September", 30);
month("October", 31);
month("November", 30);
month("December", 31);
return 0;
}
void month(apstring name, int days)
{
int i; // counter for the for loop
calender << "\n" << name << endl; // display month's name
calender << "S M T W T F S" << endl; // days of the week
calender << "-------------------" << endl;
switch (count) // sets appropriate width for each
possible day entered
{
case 0:
calender << setw(count);
break;
case 2:
calender << setw(count + 2);
break;
case 4:
calender << setw(count + 3);
break;
case 6:
calender << setw(count + 4);
break;
case 8:
calender << setw(count + 5);
break;
case 10:
calender << setw(count + 6);
break;
case 12:
calender << setw(count + 7);
break;
}
for(i = 1; i <= days; i++) // executes once for each day
{
if (i < 10) // space twice after single-digit dates calender << i << " ";
else // space once after double-digit dates. Make sense?
calender << i << " ";
count = count + 2; // increases the counter by 2
if (count == 14) // 14 = Saturday, which is the end of the week
{
calender << endl;
count = 0;
}
}
}

--------------------------------------------

This program creates a Dungeons and Dragons character sheet which becomes printed by a printer:
#include
#include
#include
#include
#include
#include
void pfunction(int,int,int,int,int,int);
int main()
{
Dice roll(18);
int st,in,dex,wis,cha,con;
apstring pquest,sent;
while (sent != "no")
{
st = roll.Roll();
in = roll.Roll();
dex = roll.Roll();
wis = roll.Roll();
cha = roll.Roll();
con = roll.Roll();
cout << "Welcome to Dungeons and Dragons. Here are your stats: " << endl;
cout << "Strength: " << st << endl;
cout << "Intelligence: " << in << endl;
cout << "Dexterity: " << dex << endl;\
cout << "Wisdom: " << wis << endl;
cout << "Charisma: " << cha << endl;
cout << "Constitution: " << con << endl;
cout << "Would you like to re-roll?" << endl;
cin >> sent;
}
cout << "Would you like this to be printed?" << endl;
cin >> pquest;
if (pquest == "yes")
pfunction(st,in,dex,wis,cha,con);
else;
return 0;
}
void pfunction(int st,int in,int dex,int wis,int cha,int con)
{
ofstream p_out;
p_out.open("LPT1");
p_out << "Strength\t\t\t" << st << endl;
p_out << "Intelligence\t\t\t" << in << endl;
p_out << "Dexterity\t\t\t" << dex<< endl;
p_out << "Wisdom\t\t\t\t"<< wis <p_out << "Charisma\t\t\t" << cha << endl;
p_out << "Constitution\t\t\t" << con << endl;
cout << "check printer" << endl;
p_out.close();
return;
}

So if you want to print a calender for any year, or a character sheet, just use these programs.