Wednesday, March 7, 2012

Array manipulation_1 (C++)




Calculating data in an assigned array, and also arranging them in neat tabular form.






//NAME: VICTOR
//PROGRAM: DEE
//COURSE CODE: CSC1183

#include "iostream"


int Array[6][6]={0,2005,2006,2007,2008,2009,1,200,210,225,300,235,2,250,465,343,255,344,3,233,333,453,268,365,4,200,325,400,333,222,5,200,160,642,674,358};
int x, i, j;
int Adding(int R);
void DisplayFunction(char&);//function to Disply the data
void CalDataFunction(char&);//Function to calculate the total rental income for each cabine
char Data[6][6];//data array
char Sum[5];
int Cabin1, Cabin2, Cabin3, Cabin4, Cabin5;//Sum for each cabine


void main()
{
    std::cout<<"++++++++++++++++++++++++++++++++++++++++++++++++++++\n"<<std::endl;
    std::cout<<"The Data Are... "<<std::endl;
    std::cout<<"____________________________________________________"<<std::endl;
    DisplayFunction(Data[6][6]);
    std::cout<<"The Total Rental Incomes Are... "<<std::endl;
    std::cout<<"____________________________________________________"<<std::endl;
    CalDataFunction(Sum[5]);
    std::cout<<"\n++++++++++++++++++++++++++++++++++++++++++++++++++++"<<std::endl;

    system("PAUSE");
}


//Function to display the data
void DisplayFunction(char&)
{
    for (x=0; x<1; x++)
        {
           
            //Loads "YEAR" ontop of the data
            if (x==0)
                std::cout<<"\t\t\t\t\tYEAR\n"<<std::endl;

                for (i=0; i<6; i++)
                {   
                   
                    switch (i)
                    {
                            //Puts the double newline between the "YEAR" and the data
                        case 1:
                            std::cout<<"\n\n\t\t";
                            break;

                            //Loads "CABINE" on the left hand side of the data
                        case 3:
                            std::cout<<"\n\tCABINE\t";
                            break;

                            //always put the newline and tablet data, at the nd of each ROW
                        case 0:case 2: case 4: case 5: case 6:
                            std::cout<<"\n\t\t";
                            break;
                    }   

                        for (j=0; j<6; j++)
                        {
                            std::cout<<Array[i][j]<<"\t";
                        }
            }
    }

    std::cout<<"\n\n"<<std::endl;
}


//Computes the total rental income for each cabine
void CalDataFunction(char&)
{
    int Adder = 0;
    for (i=0; i<6; i++)
        {   
            for (j=0; j<6; j++)
                {
                    if ((i!=0)&&(j!=0))//shaves out the year numbers and the numbering of the cabines
                    {
                        Adder = Adder + Array[i][j];//adds up the yearly income   
                    }
                }
                   
            if ((i!=0)&&(j!=0))//shaves out the year numbers and the numbering of the cabines
            {
                //displays the yearly incomes
            std::cout<<"Cabin "<<i<<"="<<Adder<<"\t";
            Adder = 0;
            }
        }
}

No comments:

Post a Comment