Tuesday, 2 July 2013

FORMATTED CONSOLE INPUT/OUTPUT FUNCTONS

//formatted console input/output functions
// width() to specify the required field size
// for displaying an output value
// precision() to specify the number of digits to
// be displayed after the decimal point
// of the float value
// fill to specify a character that is used to
// fill the unused portion of the field
// setf() to specify format flags that can control the
// form of output display(such as left justi-
// fication and right justification)
//      unsetf() to clear the flags specified
//here is the basic program of defining the field width()
/*MADE BY KRISHNA AGARWAL*/
#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    int items[4]={10,8,12,15};
    int cost[4]={75,100,60,99};
    cout.width(5);
    cout<<"ITEMS";
    cout.width(8);
    cout<<"COST";
    cout.width(15);
    cout<<"TOTAL VALUE"<<endl;
    int sum=0;
    for(int i=0;i<4;i++)
    {
        cout.width(5);
        cout<<items[i];
        cout.width(8);
        cout<<cost[i];
        int value=items[i]*cost[i];
        cout.width(15);
        cout<<value<<"\n";
        sum=sum+value;
    }
    cout<<"\ngrand total = "<<sum;
    getch();
}

No comments:

Post a Comment