Saturday, December 15, 2012

C++ TUTORIAL FOR BEGINNERS: Program to compute for Total Monthly Income (Revenue), Expenses, and Net Income (Profit)


This C++ program is a simple basic addition and subtraction operation involving a typical household monthly salary, revenue, monthly bills and expenses and the total net profit. The user is required to enter the amounts and other information. If a field which requires a data to input does not apply to a given user, 0 (zero) should be entered. An output file called "income.txt" is generated by the program to reflect the values keyed in.

Sample data input:

income.txt file:

Source code:

/*
PROGRAM 6: Monthly Net Income
AUTHOR: eternaltreasures
DATE: 2010 September 18
*/


#include <iostream>
#include <fstream>
using namespace std;

#define newline '\n'

int main ()
{

int year;
char month[10];

float Wages_Salary,
      Spouse_Child_support,
      Other_income;

float Food_Grocery,
      Mortgage_Rent,
      Transportation,
      Retirement,
      Insurance,
      Education,
      Children,
      Cable_Internet,
      Home_Cell_phone,
      Loans_Credit_cards,
      Laundry,
      Electricity,
      Gas_Heating,
      Water_bills,
      Personal,
      Clothing,
      Medical,
      Recreation,
      Donations_Gifts,
      Other_expenses;
     
float INCOME, 
      EXPENSES,
      NET_INCOME;
     
//Open the output file     
ofstream fout;    
fout.open ("income.txt");

//Welcome and instructions
cout << "Welcome to the Monthly Net Income report program!";
cout << newline;
cout << newline;
cout << "Pls. fill up all the data.";
cout << newline;
cout << "Enter 0 if not applicable.";
cout << newline;
cout << newline;

//Year and Month  
cout << "Year: "; cin >> year;
cout << "Month: "; cin >> month;
cout << newline;

//INCOME sources
cout << "MONTHLY INCOME:";
cout << newline;
cout << "Wages/Salary: "; cin >> Wages_Salary;  
cout << "Spouse/Child support: "; cin >> Spouse_Child_support;
cout << "Other income: "; cin >> Other_income;
cout << newline;

//ALL EXPENSES
cout << "MONTHLY EXPENSES:";
cout << newline;
cout << "Food/Grocery: "; cin >> Food_Grocery;
cout << "Mortgage/Rent: "; cin >> Mortgage_Rent;
cout << "Transportation: "; cin >> Transportation;
cout << "Retirement: "; cin >> Retirement;
cout << "Insurance: "; cin >> Insurance;
cout << "Education: "; cin >> Education;
cout << "Children: "; cin >> Children;
cout << "Cable/Internet: "; cin >> Cable_Internet;
cout << "Home/Cell phone: "; cin >> Home_Cell_phone;
cout << "Loans/Credit cards: "; cin >> Loans_Credit_cards;
cout << "Laundry: "; cin >> Laundry;
cout << "Electricity: "; cin >> Electricity;
cout << "Gas/Heating: "; cin >> Gas_Heating;
cout << "Water bills: "; cin >> Water_bills;
cout << "Personal: "; cin >> Personal;
cout << "Clothing: "; cin >> Clothing;
cout << "Medical: "; cin >> Medical;
cout << "Recreation: "; cin >> Recreation;
cout << "Donations/Gifts: "; cin >> Donations_Gifts;
cout << "Other expenses: ";  cin >> Other_expenses;

//Compute Total Income
INCOME = Wages_Salary
       + Spouse_Child_support
       + Other_income;

cout << newline;
cout << "TOTAL MONTHLY INCOME: " << INCOME;

//Compute Total Expenses
EXPENSES = Food_Grocery
         + Mortgage_Rent
         + Transportation
         + Retirement
         + Insurance
         + Education
         + Children
         + Cable_Internet
         + Home_Cell_phone
         + Loans_Credit_cards
         + Laundry
         + Electricity
         + Gas_Heating
         + Water_bills
         + Personal
         + Clothing
         + Medical
         + Recreation
         + Donations_Gifts
         + Other_expenses;

cout << newline;
cout << newline;
cout << "TOTAL MONTHLY EXPENSES: " << EXPENSES;

//Compute Net Income
NET_INCOME = INCOME - EXPENSES;

cout << newline;
cout << newline;
cout << "MONTHLY NET INCOME: " << NET_INCOME;
cout << newline;
cout << newline;

//Write to output file (income.txt)
fout << "Year: " << year;
fout << newline;
fout << "Month: " << month;
fout << newline;
fout << newline;

fout << "MONTHLY INCOME:";
fout << newline;
fout << "Wages/Salary: " << Wages_Salary;  
fout << newline;
fout << "Spouse/Child support: " << Spouse_Child_support;
fout << newline;
fout << "Other income: " << Other_income;
fout << newline;
fout << newline;

fout << "MONTHLY EXPENSES:";
fout << newline;
fout << "Food/Grocery: "  << Food_Grocery;
fout << newline;
fout << "Mortgage/Rent: " << Mortgage_Rent;
fout << newline;
fout << "Transportation: " << Transportation;
fout << newline;
fout << "Retirement: " << Retirement;
fout << newline;
fout << "Insurance: " << Insurance;
fout << newline;
fout << "Education: " << Education;
fout << newline;
fout << "Children: " << Children;
fout << newline;
fout << "Cable/Internet: " << Cable_Internet;
fout << newline;
fout << "Home/Cell phone: " << Home_Cell_phone;
fout << newline;
fout << "Loans/Credit cards: " << Loans_Credit_cards;
fout << newline;
fout << "Laundry: " << Laundry;
fout << newline;
fout << "Electricity: " << Electricity;
fout << newline;
fout << "Gas/Heating: " << Gas_Heating;
fout << newline;
fout << "Water bills: " << Water_bills;
fout << newline;
fout << "Personal: " << Personal;
fout << newline;
fout << "Clothing: " << Clothing;
fout << newline;
fout << "Medical: " << Medical;
fout << newline;
fout << "Recreation: " << Recreation;
fout << newline;
fout << "Donations/Gifts: " << Donations_Gifts;
fout << newline;
fout << "Other expenses: " << Other_expenses;
fout << newline;

fout << newline;
fout << "TOTAL MONTHLY INCOME: " << INCOME;

fout << newline;
fout << newline;
fout << "TOTAL MONTHLY EXPENSES: " << EXPENSES;

fout << newline;
fout << newline;
fout << "MONTHLY NET INCOME: " << NET_INCOME;
fout << newline;
fout << newline;

fout.close();

return 0;
}

1 comment:

  1. "Great tutorial on C++ for beginners! The program to compute total monthly income, expenses, and net income is really practical and useful. If you're also preparing for your GCSE Exam Preparation, don't forget to check out GCSE Feedback for additional resources and tips to help you with your studies. Keep up the excellent work!"

    ReplyDelete