Wednesday, November 6, 2013

Welcome back, all!

I will be posting my college days adventure in this blog.  So far I have taken or are taking the following classes since my return to school.
Beginning Java
Project Management
Beginning Visual Basic
Beginning C++
Introduction to Computer Security
U.S. History II

And here's a program I wrote in school that earn a grade of A and was shown to everyone in class as to the proper way to write a program.
It is a very basic C++ program.  It is self-explanatory.  You can run it if you have a C++ compiler in your computer.


/****************************************************************************
Name: John Sindayen
Class Name: CIT 133 Beginning C++
Section Number: 1001
Programming Assignment Number: 3
Date Assigned: 9/2/13
Date Due: 9/9/13
****************************************************************************/
/****************************************************************************
This C++ source code contains 3 different programs.
Variables used inside main function.
GREETING: greeting begins each program.
inputEnter: user input variable before exiting program.
****************************************************************************/

// Include header files in preprocessor directives.
#include <iostream> //Needed for input and output operations.
#include <string> //Needed to declare string objects.
#include <iomanip> //Needed to set precision for first program.

// State namespace to use in this statement.
using namespace std; //Needed to simplify syntax of iostream objects.

// Begin main function.
int main() //Main function header starts the program.
{
    //Declare named constants.
    const string GREETING= "W E L C O M E   T O   P R O G R A M   # ";

    //Welcome user to the programs.
    cout << "Welcome to our program.\n"
         << "There are three sets of programs.\n\n";

    //Greet user to first program.
    cout << GREETING << "1\n\n\n";

//***************************************************************************
// First Program: Adding Taxes To A Purchase
//
// Program asks user to enter amount of purchase for an item.
// Program then computes the federal, state and county taxes.
// This program uses a state tax of 8%, a federal tax of 12%, and a
// county tax of 3%.
// Program then displays the amount of purchase, all three taxes, and
// the purchase amount that includes all three taxes.
//
// Input variable of this program:
// purchaseAmount: purchase amount of item.
//
// Named constant variables of this program:
// FEDERAL_TAX_RATE: federal tax rate in decimal.
// STATE_TAX_RATE: state tax rate in decimal.
// COUNTY_TAX_RATE: county tax rate in decimal.
//
// Output variables of this program:
// federalTax: federal tax of item.
// stateTax: state tax of item.
// countyTax: county tax of item.
// purchaseAmountWithTaxes: final price of item including all 3 taxes.
//***************************************************************************

    //Declare named constants.
    const double FEDERAL_TAX_RATE = 0.12;
    const double STATE_TAX_RATE = 0.08, COUNTY_TAX_RATE = 0.03;

    //Declare local variables.
    double purchaseAmount; //Purchase amount of an item.
    double purchaseAmountWithTaxes; //Price including all three taxes.
    double federalTax, stateTax, countyTax;

    purchaseAmount = 0; //Initialize the purchase amount to 0.

    //Ask user to enter amount of purchase.
    cout << "Please enter the amount of purchase for the item: ";
    cin >> purchaseAmount; //Assign purchase amount to a variable.

    //Calculate all three taxes.
    federalTax = purchaseAmount * FEDERAL_TAX_RATE;
    stateTax = purchaseAmount * STATE_TAX_RATE;
    countyTax = purchaseAmount * COUNTY_TAX_RATE;
    purchaseAmountWithTaxes = purchaseAmount + federalTax + stateTax
        + countyTax; //Adds up all taxes and the purchase amount.

    //Display the purchase amount, the tax rates, the tax amounts, and
    //the final price.
    cout << setprecision(2) << fixed; //sets numbers to 2 decimal places.
    cout << "\nSUMMARY OF YOUR PURCHASE OF THE ITEM:\n\n";
    cout << "Purchase Amount of Item:       $" << purchaseAmount << endl;
    cout << FEDERAL_TAX_RATE * 100 << "% Federal Tax for Item:   $"
         << federalTax << endl;
    cout << STATE_TAX_RATE * 100 << "% State Tax for Item:      $"
         << stateTax << endl;
    cout << COUNTY_TAX_RATE * 100 <<"% County Tax for Item:     $"
         << countyTax << endl << endl; //leaves blank line.
    cout << "Final Purchase Price of Item:  $" << purchaseAmountWithTaxes
         << endl << endl; //leaves blank line.
   
    //Greet user to second program.
    cout << "\n\n" << GREETING << "2\n\n\n";

//***************************************************************************
// Second Program: Simple Word Game
//
// Program asks user to enter name, age, city, and an abbreviated college
// name.  This program assumes that none of the input values have spaces
// in them.
// Program then displays the following story replacing the user’s input
// in appropriate locations:
// A person named "name" who lived in "city" was "age" years old and goes
// to a college named "abbreviated college name".
//
// Input variables of this program:
// name: name entered by user.
// age: age entered by user.
// city: city entered by user.
// collegeName: abbreviated college name entered by user.
//
// Output variables of this program are all the input variables.
//***************************************************************************

    //Declare local variables.
    string name, city, collegeName;
    int age;

    //Ask user for name, age, city, and abbreviated college name.
    cout << "Please enter the following information:" << endl;
    cout << "Your Name: ";
    cin >> name;
    cout << "Your Age: ";
    cin >> age;
    cout << "Your City: ";
    cin >> city;
    cout << "Your abbreviated College Name (Example, CSN): ";
    cin >> collegeName;

    //Display the following story output.
    cout << "A person named " << name << " who lived in " << city
         << " was " << age << " years old and goes to a college named "
         << collegeName << "." << endl << endl;

    //Greet user to third program.
    cout << "\n\n" << GREETING << "3\n\n\n";

//***************************************************************************
// Third Program: Elapse Time In Seconds
//
// Program asks user to input the elapsed time for an event in hours,
// minutes, and seconds. The program then outputs the elapsed time in
// seconds.
//
// Input variables of this program:
// hours: hours of elapsed time.
// minutes: minutes of elapsed time.
// seconds: seconds of elapsed time.
//
// Output variable of this program:
// elapsedTimeInSeconds: total elapsed time in seconds.
//***************************************************************************

    //Declare local variables.
    int hours, minutes, seconds, elapsedTimeInSeconds;

    //Ask user to input elapsed time in hours, minutes, and seconds.
    cout << "Please enter the elapsed time for an event in hours, "
         << "minutes, and seconds.\n";
    cout << "Hours: ";
    cin >> hours; //Object cin automatically returns new line.
    cout << "Minutes: ";
    cin >> minutes; //Object cin automatically returns new line.
    cout << "Seconds: ";
    cin >> seconds; //Object cin automatically returns new line.

    //Compute elapsed time by converting hours into seconds and
    //minutes into seconds and adding all the seconds together.
    elapsedTimeInSeconds = (hours * 60 * 60) + (minutes * 60) + (seconds);

    //Display elapsed time into seconds.
    cout << "\nYour elapsed time in seconds is " << elapsedTimeInSeconds
         << " seconds.\n\n";

    //Display end of all 3 programs and end program.
    char inputEnter; //used to display the following statements.
    cout << "You have reached the end of our programming for today.\n";
    cout << "Thank you for watching and participating in these "
         << "interactive programs." << endl << endl; //double space.
    //Ask user to enter any letter to exit program.
    cout << "Please press any letter then Enter to exit program: ";
    cin >> inputEnter; //user input to exit program.

    return 0; //Tells compiler execution underwent normal success.
} //Ends main function.

John Sindayen

No comments:

Post a Comment