1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
#include <iostream>
#include <ctype.h>
#include <cstdlib>
#include <limits>
using namespace std;
// Declaring Functions.
void getAnnualIncome(int[],int);
void calcIncChange(int[],int[],int);
void calcChangePercent(int[],int[],int);
// Declaring a global variable.
int year = 0;
main(){
cout << "\t\t\t***** ABC Company Income Sheet *****\n\n\n";
// Declaring the variables and arrays that will be used in the program.
int annualIncome[10] = {0},incChange[10] = {0},percent[10] = {0};
const int arraySize = 10;
// Calling the function to get the annual income for 10 years from the user.
getAnnualIncome(annualIncome,arraySize);
cout << "\n\n";
// Calling the function to calculate increase or decrease in the annual income of the company for each year.
calcIncChange(annualIncome,incChange,arraySize);
cout << "\n\n";
// Calling The function to calculate increase or decrease percentage for each year.
calcChangePercent(incChange,percent,arraySize);
}
// Function to get annual income for 10 years.
void getAnnualIncome(int annualIncome[],int arraySize){
// NOTE: year is a global variable so i am giving the value 2000 to year in this function and will reset the value to 2000 in the next function.
year = 2000;
// Prompting the user to enter the company's annual income for 10 years one by one.
cout << "Please enter the income for past 10 years <In Million Only>: " << "\n\n";
for(int i = 0; i < arraySize; i++){
cout << "Income for year " << year << ": \t";
// This While loop checks if the character entered is an alphabet and takes the apporpriate action.
while( !(cin >> annualIncome[i]) ){
cout << "Invalid Entry Please re-enter for " << year << ": ";
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
// This while loop checks if the number is negetive and takes apporpriate action.
while(annualIncome[i] < 0){
cout << "Invalid Entry please re-enter for " << year << ": ";
cin >> annualIncome[i];
}
year++;
}
}
// Function to calculate increase or decrease in the annual income of the company for each year.
void calcIncChange(int annualIncome[],int incChange[],int arraySize){
year = 2000;
int k = 1;
// Calculating the increase or decrease for year 2000.
if(annualIncome[0] > 1000){
incChange[0] = annualIncome[0] - 1000;
cout << "Income increase in year " << year << ": \t" << incChange[0] << " million" << endl;
}
else if(annualIncome[0] < 1000){
incChange[0] = 1000 - annualIncome[0];
cout << "Income decrease in year " << year << ": \t" << incChange[0] << " million" << endl;
}
year++;
// Calculating the increase or decrease for the rest of the years.
for(int j = 0; j < arraySize - 1; j++){
if(annualIncome[j] > annualIncome[j+1]){
incChange[k] = annualIncome[j] - annualIncome[j+1];
cout << "Income decrease in year " << year << ": \t" << incChange[k] << " million" << endl;
}
else if(annualIncome[j] < annualIncome[j+1]){
incChange[k] = annualIncome[j+1] - annualIncome[j];
cout << "Income increase in year " << year << ": \t" << incChange[k] << " million" << endl;
}
year++;
k++;
}
}
void calcChangePercent(int incChange[],int percent[],int arraySize){
year = 2000;
percent[0] = (incChange[0] / 1000) * 100;
cout << percent[0];
cout << incChange[0];
}
|