Login


Lost your password?

Don't have an account ?
Register (It's FREE) ×
  


Shop
CPP: All Recent Posts Grouped
Concept Learning Code Sheets View all
Child class reading parent class methods #4676  (15-Sep-2018)
In Topic(s) : Inheritance   

#include <iostream>
using namespace std;
class FlyingThing
{
public:
int max_height(){return 11300;}
};
class Bird:public FlyingThing
{
public:
int max_wing_spread(){return 4;}
};

int main()
{
Bird b;
cout<<"Some birds can fly up to "
<<b.max_height()<<" meters."<<endl;
cout<<"Some birds can have max wing span of "
<<b.max_wing_spread()<<" meters."<<endl;
return 0;
}

Understanding how a child class object can read the parent class methods/functions easily.


Child class reading parent class data member #4673  (9-Sep-2018)
In Topic(s) : Inheritance   

#include <iostream>
using namespace std;
class Room
{
public:
int walls;
Room(){walls=4;}
};
class BedRoom:public Room
{
public:
int beds;
BedRoom(){beds=1;}
};

int main()
{
BedRoom b;
cout<<"No. of Walls = "<<b.walls<<endl;
cout<<"Bed in Room = "<<b.beds<<endl;
return 0;
}

Understanding how a child class object read the parent class data member easily.


Dynamic Polymorphism (Runtime Polymorphism) #4650  (7-Sep-2018)
In Topic(s) : Polymorphism   

#include <iostream>
using namespace std;
class Mammal
{
public:
virtual void fly(){cout<<"Mammals don't fly"<<endl;}
};
class Bat:public Mammal
{
public:
void fly(){cout<<"Bats are exceptions, they fly"<<endl;}
};

void Doesfly(Mammal *m) { m->fly();}

int main()
{
Bat b; Mammal m;
Doesfly(&m);
Doesfly(&b);
return 0;
}

Demonstration of a kind of polymorphism action when the program is rum.


Function having many forms #4646  (6-Sep-2018)
In Topic(s) : Polymorphism   

#include <iostream>
using namespace std;
void printdouble(int x)
{
cout<<2*x<<endl;
}
void printdouble(char c)
{
cout<<c<<c<<endl;
}
int main()
{
int a=12; char ch='A';
cout<<"Double of "<<a<<" is ";
printdouble(a);
cout<<"Double of "<<ch<<" is ";
printdouble(ch);
return 0;
}

Demonstration of a kind of polymorphism with multiple functions have different parameters.


Operator having many forms #4643  (6-Sep-2018)
In Topic(s) : Polymorphism   

#include <iostream>
using namespace std;
int main()
{
int a=5,b=7;
int c=a+b;
cout<<c<<endl;
string x="poly";
string y="morphism";
string z=x+y;
cout<<z<<endl;
return 0;
}

Demonstration of a kind of polymorphism with + operator.


#define Macros Nesting #4587  (2-Sep-2018)
In Topic(s) : Preprocessor Directives And Macros   

#include <iostream>
using namespace std;
#define SI(p,r,t) p*r*t/100
#define AMT(p,r,t) p+SI(p,r,t)
int main()
{
int p=203,r=5,t=2 ;
cout<<"Principal = "<<p<<endl;
cout<<"Rate = "<<r<<endl;
cout<<"Time = "<<t<<endl;
cout<<"Simple Interest = "<<SI(p,r,t)<<endl;
cout<<"Amount = "<<AMT(p,r,t)<<endl;
return 0;
}

Understanding how #define macros can be nested (use of one macros expression as a part of another macros expression)


#define directive as Macros Expressions #4585  (2-Sep-2018)
In Topic(s) : Preprocessor Directives And Macros   

#include <iostream>
using namespace std;
#define velocity(u,a,t) u+a*t
int main()
{
int v=velocity(5,2,3);
cout<<v<<endl;
return 0;
}

Understanding the purpose of #define pre-processor directive to be used as macros or use of replacement action for expressions


#define directive – Preprocessor for Names to constant replacement #4580  (1-Sep-2018)
In Topic(s) : Preprocessor Directives And Macros   

#include <iostream>
using namespace std;
#define PI 3.1416
#define R 5
int main()
{
double area=PI*R*R;
double circum=2*PI*R;
cout<<"Area of circle with radius "<<R
<<" = "<<area<<endl;
cout<<"Circumference of circle with radius "<<R
<<" = "<<circum<<endl;
return 0;
}

Understanding the purpose of #define pre-processor directive.



Finding size of enumerated data type #4567  (1-Sep-2018)
In Topic(s) : Enumerated Types   

#include <iostream>
using namespace std;
enum divisions{first=1,second=2,third=3};
int main()
{
divisions d=first;
cout<<sizeof(d)<<endl;
return 0;
}

Understanding how enum datatype is stored in memory


Solved ProblemsView all
Function overloading – Inch to centimeter conversion #4483 (26-Aug-2018)
In Topic(s) : Function Overloading Concepts   

Write two overloaded functions as follows:

Function 1:
Convert integer input parameter which is a number given as inches of some measurement to a double number which is of centimeter measurement

Function 2:
Convert double input parameter which is a number given as inches of some measurement to a double number which is of centimeter measurement

use conversion formula as 1 inch = 2.54 cm.

Also show the implementation of both the functions in the main routine.

Write two overloaded functions as follows:

Function 1:
Convert i


Error finding in function and related code #4447 (24-Aug-2018)
In Topic(s) : Number Varieties and Crunches    Functions - user defined   

Find syntactical errors in the following program and rewrite the program after underlining the corrected portion.

#include<iostreamh>
using namespace std;
void toUpper(char x) {return ((char) (x+1));}
main()
{
char c, String[]=”DOGS ARE NOT CATS”;
for(int i=0;String[i]!=;i++)
if(String[i]==’ ‘) cout<<endl;
else { c=toUpper(String[i]);cout<<c;}
return 0;
}

Find syntactical errors in the following program and rewrite the program afte


Marking header files #4445 (24-Aug-2018)
In Topic(s) : Functions (Built-in)   

Mark the name of required C++ header files for each of the following functions
strlen
getline
exit(0)
tolowerfloor

 

Mark the name of required C++ header files for each of the following function


Token Identification #4431 (23-Aug-2018)
In Topic(s) : Tokens Keyword and Identifiers   

Identify the type of token (literal, identifier, keyword, punctuator etc.) in the following
1) Case    2) { }    3) break      4) O17

Identify the type of token (literal, identifier, keyword, punctuator etc.) in


problem based on setw, setf and unsetf #4321 (15-May-2018)
In Topic(s) : Display Using IO Manipulation   

print the following table of temperature record of a patient properly using setw,setf,unsetf methods.

 

Readings   Values
-----------------
Morning     100.4
Afternoon    99.8
Evening      98.8

 

print the following table of temperature record of a patient properly using



Frequency of a given character in a sentence #3243 (2-Feb-2018)
In Topic(s) : String Handling (Null Terminated)   

Write a program to input a small sentence from the user and ask about frequency of which character is to be found. Print how many times the character occurred in the given string. Do it for a a c-style (null-terminated string). Please note that the character frequency is to be found  irrespective of its lower or upper case.

Write a program to input a small sentence from the user and ask about frequen


Suggesting Error Corrections in Natural Number Addition #3221 (31-Jan-2018)
In Topic(s) : Simple Loops   

A student has written this program to sum natural numbers from 1 to 10. His program is not giving correct results. Please help in correcting this program with right explanations as well.

A student has written this program to sum natural numbers from 1 to 10. His




Concept Notes and ResourcesView all
Basics of Inheritance in C++ #4657 (8-Sep-2018)
In Topic(s) : Inheritance   

Life is continued journey for one big reason that living beings are able to create new creatures of their own types by passing many attributes of them. This is called Inheritance.   Since Object Oriented Languages boast of modelling the real life and real problems, so they need to implement this feature called inheritance. Infacts […]


Concept of Polymorphism in C++ #4610 (6-Sep-2018)
In Topic(s) : Polymorphism   

Let us begin with understanding of the word polymorphism. The word has a greek origin from words polus/polloi and morphe. ‘Poly’ means ‘many’ and ‘Morph’ means forms. So when any entity has many forms according to its context of use, we may call it polymorphism. This nomenclature is frequently used in biological studies. For e.g. […]


As the name signifies, pre-processor directives are instructions given to compiler which it has to run before main code compilation will begin. You must be frequently seeing #include as the top of most C++ program codes. It is nothing but a pre-processor directive to tell compiler that definitions of certain classes, function and objects have […]


Concept of Enumeration in C++ #4547 (31-Aug-2018)
In Topic(s) : Enumerated Types   

Enumeration is basically a way to represent a possible list of number values for a variable in friendly names or symbol forms. For e.g. if  you have to represent rainbow colours with 0 to 6 you can always write them more meaningfully as enum rainbow { RED, ORANGE, YELLOW, GREEN, BLUE, INDIGO, VIOLET }; This […]





As C++ follows the Object Oriented Programming paradigm, it does implement the concepts of Abstraction and Encapsulation. These are interrelated concepts. First let us define them. Abstraction Abstraction is a concept where we talk about showing only the necessary part to the outside world and hide the details of implementation. Abstraction can be done for […]


C++ Header Files #4434 (23-Aug-2018)
In Topic(s) : Functions (Built-in)   

There are many built-in functions in C++ which can be used by a programmer as needed. To allow a build-in function or usage of some pre-fixed declarations C++ provides a concept of header files. Header file primarily contains the function prototypes of built-in functions so that its type checking can be performed and related library […]



Practice ProblemsView all


Finding errors in cout statements #2323 (7-Jan-2018)
In Topic(s) : Beginning to Program   

Find errors in the following cout statement constructs. 1)  cout<<“This is my work” “; 2)  cout<<\n<<“Show me next line”; 3) cout<<cout<<“This is cout chain”; 4)  cout>>a<<b; 5) return cout; 6) cout<<x=10; 7) cout<<“Student marks are “;<<marks;  








Back