Posts

Showing posts from November, 2016
For more Computer Science, Linux, C++ content visit ProgrammerCave
Follow us on Facebook | Instagram | Telegram

Contribute on Paypal

C++:Working With Files -1

Image
A program typically involves either or both of the following kind of data communication:- 1. Data transfer between console unit and program 2. Data transfer between program and disk file. Input Stream- supplies data to program or reads data from file. Output Stream- recieves data from program or writes data to file. Input operation involves the creation of an input stream and linking it with the program and input file. ________________________________________ Classes for FIle Stream Operations I/O system of c++ contains a set of classes that defines the file handling methods. These include ifstream , ofstream and fstream . These classes are derived from fstreambase class and corresponding iostream class. _________________________________________ Opening and Closing of File The filename is a string of character conatining two parts - primary name and optional period with extension. eg.  Input.data         test.doc Opening fil...

C++: Program for calculator using functions

Image
#include<iostream> using namespace std; float sum(float, float); float sub(float, float); float mul(float, float); float div(float, float); int main() { float x, y, res; char choice; cout << "Calculator\n\n"; cout << "Enter two numbers\n"; cin >> x >> y; cout << "Operations \n '+' for addition \n '-' for substraction \n '*' for multiplication \n '/' for division \n"; cin >> choice; switch (choice) { case '+': res = sum(x, y); cout << "Sum is :" << res; break; case '-': res = sub(x, y); cout << "Substraction is:" << res; break; case '*': res = mul(x, y); cout << "Multiplication is:" << res; break; case '/': res = div(x, y); cout << "Division is :" << res; break; default: cout << "Enter correct choice"; break; }...

C++: I/O Operations -2

Image
Formatted Console I/O Operations To access manipulators the file iomanip should be included in program. cout .width (w) ; to define width of a field necessary for output of item. w is field width(no. of columns) cout .precision (d) ;  to specify no. of digits to be displayed after the decimal point. By default, floating no. are printed with six digits after the decimal point.   cout.precision(3);   cout<<3.15159<<"\n";   cout<<2.50032<<"\n"; 3.142(rounded to nearest cent) 2.5 (no trailing zeros) Unlike width(), precision() retains the setting in effect until it is reset. cout .fill ( ch );  to fill unused position by any desired character. By default, the unused positions of the field are filled with the white spaces.   cout.fill("*");   cout.width(10);   cout<<5250<<"\n"; ******5250 fill() also stays in effect till we change it. cout .setf ( arg1 , arg2 );  arg1 is one of the formatti...
For more Computer Science, Linux, C++ content visit ProgrammerCave
Follow us on Facebook | Instagram | Telegram

Contribute on Paypal