Skip to main content

How to start learning Web-development

Funcation in c++ programming example in detail

Friend Funcation-

1. Adding to complex number in friend function


#include<iostream>
using namespace std;
class container
{
float a,b;
public:
void get()
{
cout<<endl<<"Enter value for A=";
cin>>a;
cout<<endl<<"Enter value for B=";
cin>>b;
}
void disp()
{
cout<<endl<<a;
cout<<endl<<b;
}
friend container addition(container,container);
};
container addition(container X,container y)
{
container Z;
Z.a=X.a+y.a;
Z.b=X.b+y.b;
return Z;
}
int main()
{
container P,Q,R;
P.get();
P.disp();
Q.get();
Q.disp();
R=addition(P,Q);
R.disp();
return 0;
}

Output -
Enter value for A=12

Enter value for B=12

12
12
Enter value for A=1

Enter value for B=1

1
1
13
13

2.  If class one is friend function of two it not means that two is friend function of one


#include <iostream>
class One
{
private:
int x;

public:
One() { x = 0; }
friend class two; //Friend Class
};

class two
{
private:
int y;

public:
void display(One &p)
{
// private members of One
std::cout << "One::x=" << p.x;
}
};

int main()
{
One x;
two y;
y.display(x);
return 0;
}

Output -
One::x=0

3.  Function overloading with return type 


#include<iostream>
using namespace std;

class addition{
public:
int sum(int A1, int A2) {
return A1+A2;
}
int sum(int A1, int A2, int A3) {
return A1+A2+A3;
}
};

int main(){
addition add;
cout<<add.sum(2,4)<<endl;
cout<<add.sum(2,4,5);
return 0;
}

Output -
6
11

Inheritance function program -


1. program of inheritance 

#include <iostream>
using namespace std;

// Base class
class first
{
public:
int a;
};

// derived class
class second:public first
{
public:
int b;
};

int main()
{
second obj;
obj.b=30;
obj.a=66;
cout<<"second b "<<obj.b<<endl;
cout<<"first a "<<obj.a<<endl;
return 0;
}

// output -->>

// second b 5
// one a 70

Structure program -

It is a user-defined datatype in c/c++ language which allows us to combine data of different data- types together. it helps to construct a complex data type which is more meaningful and It is some how very similar to an Array , but an array holds data of similar type only. But structure on the other hand, can store data of any type like integer , float , double, which is practically more useful.

For example: If I have to write a program to store Student information, which will have Student's name, age, branch, permanent address, father's name etc, which included string values, integer values etc, how can I use arrays for this problem, I will require something which can hold data of different types together.
In structure, data is stored in form of records.

Defining a structure -
struct keyword is used to define a structure. struct defines a new data type which is a collection of primary and derived datatypes

Syntax:
struct [struct_tag]
{
...
}[struct_variables];

Example of Structure -
#include <stdio.h>
#include <string.h>

struct Books {
char title_name[50];
char author_name[50];
char subject[100];
int book_id;
};

void displaybook( struct Books book );

int main( ) {

struct Books Book1;
struct Books Book2;

/* Description */
strcpy( Book1.title_name, "C/C++ Programming");
strcpy( Book1.author_name, "Developer Insider");
strcpy( Book1.subject, "C/C++ Programming Tutorial");
Book1.book_id = 6495407;

/* Description */
strcpy( Book2.title_name, "Python Programming");
strcpy( Book2.author_name, "Developer Insider");
strcpy( Book2.subject, "Python Programming Tutorial");
Book2.book_id = 6495700;

/*Display books detail*/

displaybook( Book1 );

displaybook( Book2 );

return 0;
}

void displaybook( struct Books book ) {

printf( "Book Title : %s\n", book.title_name);
printf( "Book author are : %s\n", book.author_name);
printf( "Book Subject : %s\n", book.subject);
printf( "Book Id : %d\n", book.book_id);
}

Output -

Book Title : C/C++ Programming
Book author are : Developer Insider       
Book Subject : C/C++ Programming Tutorial 
Book Id : 6495407
Book Title : Python Programming
Book author are : Developer Insider       
Book Subject : Python Programming Tutorial
Book Id : 6495700



Comments

Post a Comment

Popular posts from this blog

Why we learn REACT JS in web development

 REACT JS in web development - why we use it ? we learn REACT JS in web development because it help us to write less code and make more efficient  website because it divide code into many component which was which help us to to write less code and make more efficient work in less time you can say it is time saver if you don't want to write code from base or say scratch react js is reliable for us and very efficient for web development . What is Component means ? The meaning of component is you say in simple language is react divide the code of website let say if we want to make a website and we want to use a code repeatly so we have to write the again and again but if you was use component you have to write code at ones and use it by import it again and again you can work very efficiently and fast  What we have to do in react  In react we have to convert html form language into JSX form language and if you think how we can do this so their is many option are availabl...

Tutorial 10 text align , decoration etc explaining

 Text in Css - 1.Text color -     here we can set color in text for making them more enhancive or if we want required to change in color of text it work perfectly  syntax - color : red; OUTPUT - text color is change to red 2.Text alignment -     It is used for align the text according to the requirement and their situation we align text at center , right , left etc syntax - text-align:center; 3.Text decoration-     It is to decorate the text let if we want to underline in text then we use text decoration and make it on the line  syntax - text-decoration: underline; OUTPUT - text have an underline decoration 4.Text transformation -  In this we transform letters into uppercase , lowercase and capitalization means if the letter is small then it will convert into uppercase or visa-versa syntax - text-transform:(uppercase , lowercase , capitalize); 5.Text spacing - It decided the space between letter and words both how many gap are between...

Code of HTML and CSS how we take color , border , etc

  code of HTML and CSS - 1. How we take change color in css (color and border both property) code - <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>color in css</title> <style> .color1{ background-color: green; } .color2{ color: yellow; } .color3{ border: 2px solid red; } </style> </head> <body> <!-- lets take paragarph --> <p class="color1"> In display property if we apply inline-block property on it we can be set their width and height and element was set next to a element in line it not take extra space so in easy word it is work as both block element who's width and height can be changed </p> <p class="color2"> In display property if we apply inline-blo...