Posts

c++ program to illustrate the friend function,here we are finding mean of two numbers.

//wap in c++ to illustrate the friend function,here we are finding mean of two numbers. #include<iostream> using namespace std; class sample { int num1,num2; public : void setval(); /*here we are passing sample as argument as we are going to pass objects as argument this is the syntax of Passing Objects as Function Arguments*/ friend float mean(sample); }; void sample::setval() { cout<<"Enter two numbers"; cin>>num1>>num2; } //here we are passing x with sample as we are Passing Object(t) as Function Arguments. float mean(sample x) { return ((x.num1+x.num2)/2); } int main(){ sample s; s.setval(); //we can not write mean(s) as s.mean as this is the friend function. cout<<mean(s); }

facts about c++

Constructor constructor is a special type of function or method in which there is No return type(Even void) and constructor name will be same as the name of the class. There are two types of constructor 1.default constructor 2.parameterised constructor Passing Objects as Function Arguments in C++ class Test { public : /*here we are passing Test the name of the class as argument as we are going to pass objects as argument this is the syntax of Passing Objects as Function Arguments*/ void display(Test) }; //here we are passing t with Test as we are Passing Object (t) as Function Arguments. void Test :: display(Test t) // { ........ } Friend function A C++ friend functions are special functions which can access the private members of a class.  friend function are defined with the keyword friend  friend function return type Function name(class name); friend function is not a member of class so we don't need to write class_name or use use scop...

c++ to display the values we are passing from parameterised constructor.

//To display the values of parameterised constructor. #include<iostream> using namespace std; class add { int num1,num2,sum; public : add(int x,int y); void display(); }; add::add(int x,int y)  { num1=x; num2=y; sum=x+y;  } void add::display()  { cout<<"The nummbers are "<<num1<<"\t"<<num2<<"\n";  } int main()   {  add b=add(10,20);  b.display();   } OUT-The numbers are 10 20

c++ to calculate the sum of 2 interger no. by using constructor concept

//wap to calculate the sum of 2 interger no. by using constructor concept #include<iostream> using namespace std; class sum { int a,b,s; public: sum(int ,int ); void display(); }; sum::sum(int x ,int y) { a=x; b=y; s=a+b; } void sum::display() { cout<<"The sum is : "<<s<<"\n"; } int main() { sum ad=sum(10,20); ad.display(); return (0); } OUT- The sum is : 30 //Add two number using constructor without display function. #include<iostream> using namespace std; //class containing methods and variables. class add {     int num1,num2,sum;     public :     add(int x,int y);         }; //defining methods using scope resolution opertor. add::add(int x,int y) { num1=x; num2=y;     sum=x+y;     cout<<"The sum is : "<<sum<<"\n"; } int main() {     add b...

Some facts about java

Image
() - This is called a pair of  Parentheses ;  The  semicolon  or  semi-colon  (;)  "  double   quotation mark https://en.wikipedia.org/wiki/Quotation_mark class first character will be capital. To create an object in java class_name      object_name(as you want)   = new(keyword)    class_name (); To call variables or fields in java object_name.variable_name = value; To refer the variables of another class  first create object of that class and then call it like this object_name.variable_name=input.nextInt(); //remember we are using (.) separator operator in between object and variable name   object_name.fields_name = value; To call methods in java object_name.method_name = value; To call methods from another class first create object of that class for example if the name of the class is Add then we need to create an object  like this  Add object_name(anythin...

Deepin os does not start dual boot with windows 8 or 10 (GRUB) error solution

Image
 if you are having problem like windows is not getting started after dual booting with ubuntu then the same solution will work provide here You’ll need to boot from a live CD or USB drive, switch deepin fail safe mode.  above. Ensure the version of deepin on from a live CD or USB drive, as in the graphical method above. Ensure the version of Ubuntu on the CD is the same as the version of Ubuntu installed on your computer — for example, if you have deepin 15.03 installed, ensure you use a deepin os 15.03  live CD or usb drive. Open a terminal after booting into the live environment. Identify the partition deepin is installed on using one of the following commands: sudo fdisk -l sudo blkid Here’s the output of both commands. In the fdisk -l command, the deepin partition is identified by the word Linux in the System column. In the blkid command, the partition is identified by its ext4 file system.Run the following command to mount the deepin ...

Java Program to Add Two Numbers using different methods(methods in different ways)

Simple Java Program to Add Two Numbers This simple Java program let the user to enter two integer values and then add those two numbers and assign it to variable sum. JAVA CODE: //Addition of two numbers by taking input from user. import java.io.*; import java.util.*; class Add_Two_Num_input{     public static void main(String args[]){         int num1,num2,sum;         System.out.println("Enter two numbers ");         Scanner input= new Scanner(System.in);         num1=input.nextInt();         num2=input.nextInt();         sum=num1+num2;         System.out.println("The sum of the number is "+sum);             } } OUT- Enter two numbers 78 8 The sum of the number is 86 Java Program to Add Two Numbers us...