Skip to main content

Posts

Showing posts from August, 2018

Static variables....

STATIC VARIABLES Static variables are very crucial in cpp language and also for building logics for a company. Today, we will see a code first and then we will discuss the static variables. #include <iostream> #include <string> using namespace std; class people {        string address;//privately called//        string name;//privately called// public :        static int id;// prototype of declaring a static variable//        people( string name , string address )//Parameterized constructor which sets the //value for name and address//        {              ++id;// increment of that static variable as a new person comes to join..//              this ->name = name ;//se...

Class Containership

Class Container-ship in c++ Needed skills: Basic knowledge on class Inheritance  Access Modifiers  Today we will discuss about class container-ship in cpp program. Now the question arises. Why we should focus on class container-ship? I assume that we can access any variables through class and inheritance. But sometimes, using inheritance make your code broad without any needs. You can use container-ship on that purpose.  Now, let's talk about the purpose.  I will give an example and through that I will make you guys understand the purpose of using class container-ship.  Suppose, you are a rich man. And you have a lot of property. You have two cars. one is Ferrari and other is Audi. Now, you want to know the number of wheels and oil method(diesel or patrol) And you will assign those things according to your name and address.  It's highly recommended to practice this code without solution. Now, we can do this in two ...
We want to discuss a diamond problem. Which will cover inheritance,virtual class(2 topics).For this I will use CPP(c++) You have to have a common idea of inheritance in cpp for this. Now, why we name this as a diamond problem? Good question. Actually, the hypothetical figure is like a diamond. 😂😂.ok lets see the figure. Let's assume that we have 4 class. a,b,c,d. b and c will inherit a and d will inherit both c and b Now, I will upload the code which is simply inheritance.. #include<iostream> using namespace std; class a { protected: int apr; public: void set_apr(int apr) { this->apr = apr; } int get_apr() { return apr; } }; class b : public a { protected: int bpr; public: int bpub; void set_bpr(int bpr) { this->bpr = bpr; } int get_bpr() { return bpr; } }; class c : public a { protected: int cpr; public: int cpub; void set_cpr(int cpr) { this->cpr = cpr; } int get_cpr() { return...