Posts

Showing posts from September, 2016

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 scope res

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=add(10,20);      }     OUT- The sum is :

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(anything you want) = new Add(); now call it in another class with this object_name.method_name

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 partition at /

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 using Methods import java.io.*; import java.util.*; class AdditionOops {          public static void main(String args[])     {   int num1,num2;        System.out.println("Enter two numbers");        Scanner

write a c++ program to find whether a number is positive or negative.

Source code- #include<iostream> using namespace std; int main(){ int number; cout<<"Enter a number "; cin>>number; if(number>0) cout<<"Negative"; else cout<<"Positive"; } OUTPUT- Enter a number 5 Negative

write a c++ program to find odd numbers in range.

Source code- #include<iostream> using namespace std; int main(){ int min,max,num; cout<<"Enter minimum range "; cin>>min; cout<<"Enter maximum range "; cin>>max; for(num=min;num<=max;num++) if(num%2!=0) cout<<num<<"\t"; } OUTPUT- Enter minimum range 1 Enter maximum range 10 1 3 5 7 9

Program name:-write a c++ program to convert celsius to fahrenheit and vice versa.

Sourcee code - #include<iostream> using namespace std; float celsius_To_Fahrenheit(float celsius); float fahrenheit_To_celsius(float fahrenheit); int main(){ float celsius,fahrenheit,celsi,entered_fahrenheit; cout<<"Enter celcius to convert to fahrenheit "; cin>>celsius; fahrenheit=celsius_To_Fahrenheit(celsius); cout<<fahrenheit; cout<<"\nEnter fahrenheit to convert to celsius "; cin>>entered_fahrenheit; celsi=fahrenheit_To_celsius(fahrenheit); cout<<celsi; } float celsius_To_Fahrenheit(float celsius){ float fahrenheit; //T(°F) = 20°C × 9/5 + 32 = 68 °F fahrenheit=((celsius*9)/5)+32; return fahrenheit; } float fahrenheit_To_celsius(float entered_fahrenheit){ float celsi; //T(°C) = (68°F - 32) × 5/9 = 20 °C celsi=((entered_fahrenheit-32)*5)/9; return celsi; } OUTPUT- Enter celcius to convert to fahrenheit 20 68 Enter fahrenheit to conve

How to setup manual-config-for-linux-with-openvpn

Install and set up the VPN Start a Terminal session. In the Terminal, type the following commands. To install OpenVPN, type    centos  INSTALL OpenVPN ® PLUGIN FOR  NETWORK MANAGER Find the Terminal option on the left side bar. Type: sudo yum -y  install  epel-release and press Enter. Type in your root password and press Enter. Type: sudo yum -y  install NetworkManager - openvpn NetworkManager - openvpn - gnome  and press Enter. sudo apt-get install -y openvpn Go to the folder where you have openvpn config file right click there and select open in terminal then select the open vpn file and choose rename and copy the full name (with .ovpn) and paste with sudo openvpn --config (config file name)

Using the pow()-method in Java(power)

Use  Math.pow(double, double) , or statically import  pow  as such: import static java . lang . Math . pow ;

c++ program price of a book using class and object

/*To define a class book private book no.-int price-float booktitle-char no. of copies getdata display */ #include<iostream> using namespace std; class Book{ int Book_num,Quantity_Book; char Book_Title[20]; float price; public: void Input(); float Total_Cost() { float cost=Quantity_Book * price; return cost; } void Display(); }; void Book::Input(){ cout<<"Number of books "; cin>>Book_num; cout<<"Title of the Book "; cin>>Book_Title; cout<<"Quantity of Book "; cin>>Quantity_Book; cout<<"Enter the Price of Book "; cin>>price; } void Book::Display(){ cout<<"Numbers of Books "<<Book_num<<endl; cout<<"Title of Book "<<Book_Title<<endl; cout<<"Quantity of Book "<<Quantity_Book<<endl; cout<<"Total cost is "<<Total_Cost(); } int m

c++ program to print Average of a batsman using classes and objects.

/*write a c++ program to define a class batsman with the following information private variable bcode 4 digit,bname 20 char,innings,notout,bat avg(float) which calculated(runs/(innings-notout))byfunction calc_avg public member : readdata() to accept values of bcode,bname,innings,notout,runs and invoke calc_avg to calculate the avg. display() to display */ #include<iostream> using namespace std; class Batsman{ int bcode,innings,notout,runs; float bat_avg; char bname[20]; float calc_avg()     { bat_avg =(float) runs/((float) innings -(float)notout); return bat_avg; } public: void readData(); void display(); }; void Batsman::readData(){ cout<<"Enter batsman code "; cin>>bcode; cout<<"Enter batsman name "; cin>>bname; cout<<"Enter innings "; cin>>innings; cout<<"Enter not outs "; cin>>notout; cout<<"Enter runs &quo

java programs for printing from 1 to 100

*/ prime number is a number which is divisible by 1 and itself, example 2,3. for printing prime number from 1 to 3 we need to devide 1 by 1 ,2 by 1 and 2 both and 3 by 1,2,and 3. Remember 1 is not considered as prime number. so we will start from 2 so 2 is divisible by 1 and 2 exactly two times so 2 is prime number. in case of 3, 3 is divisible by 1 but not divisible by 2 and again 3 is divisible by 3 ,so here we can see that 3 is divisible by 1 and 3 exactly two divisible 2 times so 3 is prime. */ import java.io.*; import java.util.*; class Prime1To100{ public static void main(String args[]){   int i,j,num=100,flag; for(i=1;i<=num;i++) {     //when i will be incremented from 1 to 2 flag will be reset to 0 that's why we are initializing flag here.      flag=0;   for(j=1;j<=i;j++) { if(i%j==0) flag++; } if(flag==2) { System.out.println(i+" "); } } } } out-2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97

java program for finding Area of rectangle and square using constructor overloading

 /*Area and perimeter of rectangle and square using constructor overloading. Constructor overloading means there will be two or more constructor and the name of all constructors will be same only number of arguments will be different. when you pass arguments value in the constructor it matches the number of arguments value with the defined constructor arguments and executes that constructor automatically Here Box is constructor. */ //Area of rectangle and square using constructor overloading. import java.io.*; import java.util.*; //Instance variable  of Box. class Box{ double length; double width; //Constructor for rectangle when two parameter are passed (area). Box(double l,double w){ length=l; width=w; } double AreaRectangle(){ return length*width; } //Constructor for square when one value is initialized(area). Box(double l){ length=l; } double AreaSquare(){ return length*length*length; } } //Main class from where program execution begins class Square_Rectangle_Const_Overloading{

java program for Area and perimeter of rectangle and square using constructor overloading

/*Area and perimeter of rectangle and square using constructor overloading. Constructor overloading means there will be two or more constructor and the name of all constructors will be same only number of arguments will be different. when you pass arguments value in the constructor it matches the number of arguments value with the defined constructor arguments and executes that constructor automatically Here Box is constructor. */ import java.io.*; import java.util.*; //Instance variable  of Box. class Box{ double length; double width; //Constructor for rectangle when two parameter are passed (area). Box(double l,double w){ length=l; width=w; } //method for calculating area of rectangle. double AreaRectangle(){ return length*width; } //method for calculating permeter of rectangle. double PerimeterRectangle(){ return 2*(length + width); } //Constructor for square when one value is initialized(area). Box(double l){ length=l; } //method for calculating

java program of Box using constructor overloading

//Constructor overloading using Box for no parameter for one parameter and for all parameters. import java.io.*; import java.util.*; class MyBox{ double length; double depth; double width; //Constructor called when all three dimesions are apecified. MyBox(double l,double d,double w){ length = l; depth = d; width = w; } //Defining method to calculate vol. double vol1(){ return length*width*depth; } //Constructor when no parameters is initialized. MyBox() { //-1 to indicate an uninitialized box. width=-1; depth=-1; length=-1; } //Defining method to calculate vol. double vol2(){ return -1; } //Constructor used when only one value is initialized. MyBox(double l){ length = l; } //Defining method to calculate vol. double vol3(){ return length*length*length; } } class Box_Const_Overloading{ public static void main(String args[]){ MyBox Box1=new MyBox(10,20,15); MyBox Box2=new MyBox(); MyBox Box3=new MyBox(7); System.out.println("vol is "+Box1.vol1()); System.out.println("Vol i

java program for box using constructor

//program for box using constructor import java.io.*; import java.util.*; class MyBox{     double length;     double breadth; MyBox(double l,double b){     length=l;     breadth=b; }     double vol(){         return length * breadth;     } } class Box{     public static void main(String args[]){     MyBox rectangle=new MyBox(10,20);     System.out.println("vol is "+rectangle.vol()); } }    OUTPUT- vol is 200.0

java program for printing binary right angled traingle

/* 1 1 0  1 0 1 1 0 1 0 1 0 1 0 1 */ import java.io.*; import java.util.*; public class Binary_triangle { public static void main(String[] args) {                 int num,row,coloumn;         System.out.println("Enter the size of row");         Scanner sc=new Scanner(System.in);         num=sc.nextInt();         for(row=1;row<num;row++)         {             for(coloumn=1;coloumn<=row;coloumn++)                 System.out.print(coloumn % 2+"\t");                 System.out.print("\n");                 }            }     }