The cin and cout entities (they are not statements) are C++ iostream library objects that allows access to "standard input" and "standard output". In C++, the statement cout << "Hello World!"; is similar to the C statement printf("Hello World!\n"); Similarly, cin >> variable; allows reading from standard input to a variable.
To use these you must use:
#include <iostream>
then define a variable, doesn't matter what type, could be anything (int, char, char*) like so:
int a;
int b;
To get the values for these you must use cin:
cin >> a;
cin >> b;
The to output them once they have been allocated a value:
cout >> a;
cout >> b;
or you could do math with them such as:
cout << (((a+b)b)/a)b To use these you must use:
#include <iostream>
then define a variable, doesn't matter what type, could be anything (int, char, char*) like so:
int a;
int b;
To get the values for these you must use cin:
cin >> a;
cin >> b;
The to output them once they have been allocated a value:
cout >> a;
cout >> b;
or you could do math with them such as:
cout << (((a+b)b)/a)b
Yes. In actual fact that is the only place you can use them, period.
Function is a logically grouped piece of code allowing perform certain types of operations. Function can return value (int, double etc) or be void type - meaning they do not return value. Functions allow to make code cleaner by moving out chunks of code of main body. For instance you want to write a function that finds area of rectangular. #include <iostream> using std cin; using std cout; using std endl; using std get; int main() { double sideA = 0.0; cout << "Enter side a of rectagular: "; cin >> sideA; double sideB = 0.0; cout << endl << "Enter side b of rectangular: "; cin >> sideB; //This part passes sides a and b to user defined function "Square" cout << endl << "Area of rectangular is: " << Square(a, b); cin.get(); return 0; } //definition of user defined function Square double Square(double a, double b) { return (a * b); }
user defined functions r d functions whch user declare before the main functn in c program... for eg. double min( doub;le x,double y); int factorial( ,) int square(int) etc
A namespace is similar to a class in object oriented programming. A namespace contains functions defined by the programmer. for example namespace std contains functions like cout and cin.namespaces can be globaly declared like so: "using namespace std;"which includes all the functions located in the namespace std.if you only need to use cout you can globaly declare only cout like this "using std::cout;"orstd::cout
Predefined codes or the predefined functions are the codes small or large codes which are predefined by the maker of the language. In C++ the predefined codes can be included in the program by the header files. These codes are placed in files and functions could be used to access them. Like a simple console Code to output "Hello World" uses a predefined code cout
This are the predefined functions in c, which are already write.Examples : printf(),scanf().
COUT is an inbuilt function in c++ language. Cout is used to print something on to the standard output.
Function is a logically grouped piece of code allowing perform certain types of operations. Function can return value (int, double etc) or be void type - meaning they do not return value. Functions allow to make code cleaner by moving out chunks of code of main body. For instance you want to write a function that finds area of rectangular. #include <iostream> using std cin; using std cout; using std endl; using std get; int main() { double sideA = 0.0; cout << "Enter side a of rectagular: "; cin >> sideA; double sideB = 0.0; cout << endl << "Enter side b of rectangular: "; cin >> sideB; //This part passes sides a and b to user defined function "Square" cout << endl << "Area of rectangular is: " << Square(a, b); cin.get(); return 0; } //definition of user defined function Square double Square(double a, double b) { return (a * b); }
user defined functions r d functions whch user declare before the main functn in c program... for eg. double min( doub;le x,double y); int factorial( ,) int square(int) etc
type function_name (type1 arg,...){//function body}void finc(int arg0){cout
A namespace is similar to a class in object oriented programming. A namespace contains functions defined by the programmer. for example namespace std contains functions like cout and cin.namespaces can be globaly declared like so: "using namespace std;"which includes all the functions located in the namespace std.if you only need to use cout you can globaly declare only cout like this "using std::cout;"orstd::cout
Predefined codes or the predefined functions are the codes small or large codes which are predefined by the maker of the language. In C++ the predefined codes can be included in the program by the header files. These codes are placed in files and functions could be used to access them. Like a simple console Code to output "Hello World" uses a predefined code cout
cin and cout are synonymous with stdin and stdout, implementing console input and output respectively.
This are the predefined functions in c, which are already write.Examples : printf(),scanf().
It's an object of the class ostream.
Either you can use the pre defined function "pow" in the <math.h> header file OR you can make a user defined function to do the same operation. 1.Using the pre defined function in <math.h> : The function is a of datatype double and accepts only values in double. So, prototype declaration is: double pow(double x,double y); Pass the values to the function and it'll return the value of xy. In the calling function it can be declared as: double power=pow(x,y); 2.USER DEFINED FUNCTION: double power(double x,int y); int main() { double x,result; int y; cout<<"\nEnter the base: "<<; cin>>x; cout<<"\nEnter the exponential power: "; cin>>y; result=power(x,y); cout<<"The result of x to the power y is: "<<result; return 0; } double power(double x,int y) { for(int i=0;i<=y;i++) { x*=x; } return x; }
Most functions are available from libraries, however some functions are built-in to the compiler itself. A built-in function is therefore an intrinsic function. Some intrinsics are only available as built-in functions while others also have standard function equivalents. You can choose to use some or all intrinsics either by using the #pragma compiler directive or via a compiler optimisation switch, such as /Oi in MSVC++, or indeed both. Intrinsic functions are typically inline expanded to eliminate the overhead of a function call, and some will also provide information back to the compiler in order to better optimise the emitted code. Intrinsics affect the portability of code but are generally more portable than inline assembler. Indeed, some architectures do not support inline assembler, thus intrinsics are nothing if not essential where optimal code is a requirement. Your compiler's documentation should provide a complete list of the intrinsic functions available for each platform it supports, along with the standard function equivalents.
In C++: #include <iostream> using namespace std; int main() { int x, y; char func; cout << "Enter a number: "; cin >> x; cout << "Choose Function: "; cin >> func; cout << "Enter another number: "; cin >> y; switch(func) { case '+': cout << x + y << endl; break; case '-': cout << x - y << endl; break; case '*': cout << x * y << endl; break; case '/': cout << x / y << endl; break; default: cout << "Invalid Function!" << endl; break; } char wait; cin >> wait; return 0; }