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
Finding required libraries based on functions used #5607  (31-Dec-2018)
In Topic(s) : Functions (Built-in)   

Ronica Jose has started learning C++ and has typed the following program. When she compiled the following code written by her, she discovered that she needs to include some header files to successfully compile and execute it. Write the names of those header files, which are required to be included in the code.

void main()
{
  double X,Times,Result;
  cin>>X>>Times;
  Result=pow(X,Times);
  cout<<Result<<endl;
}

Multiple value assignment attempts #5571  (19-Dec-2018)
In Topic(s) : Operators   

Here we demonstrate the treatment of precedence between comma, brackets and assignment operator in a multiple value assignment scenario.


Assignment operator chain #5511  (17-Dec-2018)
In Topic(s) : Operators   

Here we demonstrate the assignment done in a chain fashion.


Child class reading parent class methods #4676  (15-Sep-2018)
In Topic(s) : Inheritance   

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   

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   

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


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

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


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

Demonstration of a kind of polymorphism with + operator.


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

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   

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


Solved ProblemsView all
04C-2018S #6698 (19-Jan-2019)

Consider the following class Item:-

class Item
{
  int ItemId;
  int Quantity;
  float Price;
public:
  void NewItem()
  {
    cin>>ItemId>>Quantity>>Price;
  }
void ShowItem()
  {
    cout<<ItemId<<":"<<Quantity<<":"<<Price<<endl;
  }
void Set_Price(float P)
  { Price=P;
  int Ret_Id()
  { return ItemId; }
};

Write a function named Change_Item(int Id, float Pr) to modify the price of the item whose Itemid & new price are passed as an argument.

Consider the following class Item:-

class Item
{
  int ItemId;
  			
		

04B-2018S #6696 (19-Jan-2019)

Write a user-defined function named Count() that will read the contents of text file named “Report.txt” and display the count of the number of lines that start with either „I. or „M..
E.g. In the following paragraph, there are 3 lines starting with „I. or „M.:
“India is the fastest growing economy.
India is looking for more investments around the globe.
The whole world is looking at India as a great market.
Most of the Indians can foresee the heights that India is capable of reaching.”

Write a user-defined function named Count() that will read t


04A-2018S #6694 (19-Jan-2019)

Answer the questions (i) & (ii) in the program segment given below for the required task.

class Route
{
  int Route_No;        //Route Number
  char Route_name[21]; //Name of Route
  int No_Kms;          // Distance in kms on Route
public;
  void New_Route();    // Accepts details of new Route
  void Show_Route();   // Display details of a Route
  int Get_RouteNo();   //Return the Route Number
  {  return Route_No;  }
void Update_Kms(int K)
  { No_Kms=K;}
};
void Update_Route(int No, int New_Kms) //Update No_Kms of a Route
{
  Route R;
  fstream File("ROUTE.DAT" , ios::in | ios::out | ios::binary);
  while(!File.eof())
  {
    File.read((char*)&R, sizeof(R));
    if(( R.Get_RouteNo()==No))
    { R.update_Kms(New_Kms);
    ___________________   //Statement 1
    ___________________   //Statement 2
    cout<<"Route Details updated\n";
  }
}
File.close();
} 

 

(i) Write Statement 1 to position the file pointer to the appropriate place so that the data updation is done for the correct Route.
(ii) Write Statement 2 to perform the write operation so that the updation is done in the binary file “ROUTE.DAT”.

Answer the questions (i) & (ii) in the program segment given below for th


03E-2018S #6691 (19-Jan-2019)

Evaluate the following POSTFIX expression. Show the status of Stack after execution of each operation separately:
TRUE, FALSE, OR, NOT, TRUE, FALSE, AND, OR

Evaluate the following POSTFIX expression. Show the status of Stack after exe


03D-2018S #6675 (19-Jan-2019)

Write the definition of a user-defined function REPEAT_ROW(int A[][3],int R, int C) in C++ that will store the elements in the following manner
1. All row elements except the 1st element replaced by the 1st element,
2. All row elements except the 1st & 2nd element replaced by the 2nd element,
3. All row elements except the 1st , 2nd & 3rd element replaced by the 3rd element and so on.
For example: if initially the array was:-

5 6 10 2
2 6 9 12
18 14 5 6

Then, the contents of the array after execution of the above function will be:-

5 5 5 5
2 6 6 6
18 14 5 5

Write the definition of a user-defined function REPEAT_ROW(int A[][3],int R,


03C-2018S #6671 (15-Jan-2019)

Write the definition of a member function Q_Insert() for a class Exam_Queue in C++ to insert a new Application information in a dynamically allocated queue whose code is already given below as a part of the program(assume all necessary header files are included in program):

struct Application
{
  int App_Id;
  char App_Name[21];
  Application *Link;
};
class Exam_Queue
{
  Application *Front, *Rear;
public;
  Exam_Queue()   //Constructor
  {
  Front=Rear=NULL;
  }
  void Q_Insert ();
  void Q_Delete();
};

Write the definition of a member function Q_Insert() for a class Exam_Queue i


03B-2018S #6669 (15-Jan-2019)

An array A[50][30] is stored along the row in the memory with each element requiring 4 bytes of storage. If the element A[10][15] is stored at 21500, then find out the base address of the array and the memory address of element stored at location A[30][25]?

An array A[50][30] is stored along the row in the memory with each element re


03A-2018S #6667 (15-Jan-2019)

Write the definition of function named Array_Swap() that will accept an integer array & its size as arguments and the function will interchange/swap elements in such a way that the first element is swapped with the last element, second element is swapped with the second last element and so on, only if anyone or both the elements are odd.
E.g. if initially array of seven elements is:
5, 16, 4, 7, 19, 8, 2
After execution of the above function, the contents of the array will be:
2,16, 19, 7, 4, 8, 5

Write the definition of function named Array_Swap() that will accept an integ


02D-2018S #6664 (15-Jan-2019)
Answer the question from (i) to (iv) based on the given below code
(assume all necessary header files are included in program):-

class City
{
  int City_Id;
  char City_Name[30];
protected:
  int City_Population;
public:
  City();
  void Get_Population();
  void New_City();
  void Show_City;
};
class State : public City
{
  int State_Id;
  char State_Name[25];
protected:
  int State_Population;
public:
  State();
  void New_State();
  void Print_State();
};
class Country : private State
{
  int Country_Id;
  char Country_Name[25];
public;
  Country();
  void New_Country();
  void Display_Country();
};

 

(i) Write name of the class whose constructor is invoked first on the creation of a new object of class Country.
(ii) Write name of the data members which are accessible through the object of class Country.
(iii) List name of the members which are accessible through the member function “void New_Country()”.
(iv) What will be the size(in bytes) of an object of class Country & State respectively.

Answer the question from (i) to (iv) based on the given below code
(assume			
		

02C-2018S #6661 (15-Jan-2019)

Define a class Bill in OOP with the following specification:-
Private members:
1. Bill_no – type long(bill number)
2. Bill_period – type integer(number of months)
3. No_of_calls – type integer(number of mobile calls)
4. Payment_mode – type string(“online” or “offline”)
5. Amount – type float(amount of bill)
6. Calculate_Bill() function to calculate the amount of bill given as per the following conditions:

No_of_calls Calculation Rate/call
(in rupees)
<=500 1.0
501-1200 2.0
>1200 4.0

Also, the value of Amount should be reduced by 5% if Payment_mode is “online”.
Public members:
1. A member function New_Bill() that will accept the values for Bill_no, Bill_period, No_of_calls, Payment_mode from the user and invoke Caluclate_Bill() to assign the value of Amount.
2. A member function Print_Bill() that will display all details of a Bill.

Define a class Bill in OOP with the following specification:-
Private m


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