Posts

C++ Function: Overloading Example

#include <iostream>   using namespace std ;   /* Number of arguments are different */   void display ( char [ ] ) ; // print the string passed as argument void display ( char [ ] , char [ ] ) ;   int main ( ) { char first [ ] = "C programming" ; char second [ ] = "C++ programming" ;   display ( first ) ; display ( first, second ) ;   return 0 ; }   void display ( char s [ ] ) { cout << s << endl ; }   void display ( char s [ ] , char t [ ] ) { cout << s << endl << t << endl ; }

C++ Function: Print 45 Asterisks for Design the output

using namespace std; void starline( ); into main () { starline ( ); cout << "Data type Range" << endl; starline ( ); cout << "char -128 to 127 " << endl << "short -32 ,768 to 32,767"<< endl << "int system independent: << endl << " long q-2,147,483,648 to 2,147,483,647" << endl; starline ( ); return 0; } //"""""""""""""""""""""""".. //starline ( ) // function defintion void starline ( ) { for(into j=0;j<45; j++) cout << "*" ; cout << endl; }      The output from the program looks like this ************************************* Data type Range ************************************* Char -128 to 127 Short -32,768 to 32,767 Into system dependent Double -2,147,483,648 to 2,147,483,647 *******

C++ Function: Adding Two Numbers with default value parameter

#include <iostream> using namespace std ; int sum ( int a , int b = 20 ) { int result ; result = a + b ; return ( result ); } int main () { // local variable declaration: int a = 100 ; int b = 200 ; int result ; // calling a function to add the values. result = sum ( a , b ); cout << "Total value is :" << result << endl ; // calling a function again as follows. result = sum ( a ); cout << "Total value is :" << result << endl ; return 0 ; }

C++ Function : Find Maximum value between two natural numbers

#include <iostream> using namespace std ; // function declaration int max ( int num1 , int num2 ); int main () { // local variable declaration: int a = 100 ; int b = 200 ; int ret ; // calling a function to get max value. ret = max ( a , b ); cout << "Max value is : " << ret << endl ; return 0 ; } // function returning the max between two numbers int max ( int num1 , int num2 ) { // local variable declaration int result ; if ( num1 > num2 ) result = num1 ; else result = num2 ; return result ; }

Char Array Calculation

Write a C++ program which will accept an expression as input and performs the operation based on operators and operands. Sample input:  c = a * 3 + b / 2 (white space is not allowed)  Hints: Char Array / String Array will be required to perform this operation.

Fahrenheit to Celsius (ºF to ºC)

Image
Answer: Source Code #include<stdio.h> main() { float farenheit,celsius; printf("Enter the temp of city in Farenheit:"); scanf("%f", &farenheit); celsius = (5.0/9.0) * (farenheit-32); printf("Temperature in Celsius: %f",celsius); }

C++ : Interview Questions on "Types"

Here is a listing of C++ interview questions on “Types” along with answers, explanations and/or solutions: 1. What is the size of wchar_t in C++? a) 2 b) 4 c) 2 or 4 d) based on the number of bits in the system Answer:d Explanation:Compiler wants to make CPU as more efficient in accessing the next value. 2. Pick the odd one out a) array type b) character type c) boolean type d) integer type Answer:a Explanation:array type is not the basic type and it is constructed using the basic type. 3. which datatype is used to represent the absence of paramaters? a) int b) short c) void d) float Answer:c Explanation:void will not return anything. 4. What does a escape code represent? a) alert b) backslash c) tab d) form feed Answer:a Explanation:Because a is used to produce a beep sound. 5. Which type is best suited to represent the logical values? a) integer b) boolean c) character d) all of the mentioned Answer:b Explanation:Logical values can b