Search This Blog

Saturday, 1 January 2022

Title: Implementation of java.util package.

 Title: Implementation of java.util package.

Aim: - To study Scanner class in Java.

Theory:-

Package

                A java package is a group of similar types of classes, interfaces, and sub-packages. Package in java can be categorized in two forms, built-in package, and user-defined package.

There are many built-in packages such as java, java.lang, java.awt, java.swing, java.net, java.io, java.util, java.sql etc.

Advantage of Java Package

1) Java package is used to categorize the classes and interfaces so that they can be easily maintained.

2) Java package provides access protection.

3) Java package removes naming collision.

Java Scanner:- 

                Scanner class in Java is found in the java.util package. Java provides various ways to read input from the keyboard, the java.util.Scanner class is one of them. The Java Scanner class provides nextXXX() methods to return the type of value such as nextInt(), nextByte(), nextShort(), next(), nextLine(), nextDouble(), nextFloat(), nextBoolean(), etc. To get a single character from the scanner, you can call next().charAt(0) method which returns a single character.


                How to get Java Scanner:- To get the instance of Java Scanner which reads input from the user, we need to pass the input stream (System. in) in the constructor of the Scanner class. Syntax: Scanner in = new Scanner(System.in);

Program:-

1st program

package Section7; 

import javax.lang.model.element.Name; 

import java.util.Scanner; 

public class Main { 

    public static void main(String[] args) 

    

        String name; 

        int Roll_No; 

        float Percentage; 

        long Mobile_No; 

        char Gender; 

        double cgpa; // Creating Object for scanner class Scanner 

        sc = new Scanner(System.in); 

        System.out.println("Enter Your Name: "); 

        name = sc.next(); 

        System.out.println("Enter Roll No: "); 

        Roll_No = sc.nextInt(); 

        System.out.println("Enter Percentage: "); 

        Percentage = sc.nextFloat(); 

        System.out.println("Enter Mobile Number: "); 

        Mobile_No = sc.nextLong(); 

        System.out.println("Enter Gender: "); 

        Gender = sc.next().charAt(0); 

        System.out.println("Enter CGPA: "); 

        cgpa = sc.nextDouble(); 

        System.out.println("Name: " + name + " Roll No: " + Roll_No + " Percentage: " + Percentage + "                 Mobile No: " + Mobile_No + " Gender: " + Gender + " CGPA: " + cgpa); 

    

}


Output:





2nd Program: Even Or Odd

package Section7; 
import java.util.Scanner; 
public class EvenOddProgram {
     public static void main(String args[])
     { 
        / / Creating Object Of Scanner Class Scanner 
            Number = new Scanner(System.in); 
            System.out.println("Enter An Integer Number: "); 
            int Num = Number.nextInt(); 
            if (Num % 2 == 0)
             {
                     System.out.println("Even Number: " + Num); 
                }
             else
             {
                     System.out.println("Odd Number: " + Num);
                 }
       
}

Output:


3rd Program:Linear Search

package Section7; 
import java.util.Scanner; 
public class LinearSearch 
{
     public static void main(String args[]) 
     {
             int n, x, flag=0, i;
             // Creating Object Of Scanner Class Scanner 
            Sc = new Scanner(System.in); 
            System.out.println("Enter Number Of Elements: ");
             n = Sc.nextInt(); 
            int a[] = new int[n]; 
            System.out.println("Enter Elements of An Array: ");
             for (i = 0; i < n; i++)
             {
                 a[i] = Sc.nextInt(); 
              
            System.out.println("Enter Element To Be Searched: ");
             x = Sc.nextInt(); 
            for (i = 0; i < n; i++)
             { 
                    if (a[i] == x) 
                    
                            flag = 1; 
                            break; 
                    }
                     else
                     {
                             flag = 0; 
                    
                }
                 if (flag == 1) 
                {
                         System.out.println("Element Is Present: ");
                 }
                 else
                 {
                             System.out.println("Element Not Present: ");
                 }
          }
 }
 Out Put:


Title: Implementation of jolly jumper sequence problem.

Title: Implementation of jolly jumper sequence problem.
Aim: - To study the jolly jumper sequence problem using an array.
Theory:-

            A sequence of n > 0 integers is called a jolly jumper if the absolute values of the difference between successive elements take on all the values 1 through n-1. For instance,
1 4 2 3
            Is a jolly jumper, because the absolute differences are 3, 2, and 1 respectively. The definition implies that any sequence of a single integer is a jolly jumper. You are to write a program to determine whether or not each of a number of sequences is a jolly jumper.

Input
Each line of input contains an integer n <= 3000 followed by n integers representing the sequence.
Output
For each line of input, generate a line of output saying "Jolly" or "Not jolly".
Sample Input
4 1 4 2 3
5 1 4 2 -1 6
Sample output
Jolly
Not jolly


Program:

#include<iostream>
#include<cmath>
using namespace std;
bool isItJolly(int diff[],int n)
{
for(int i=0;i<n-1;i++)
{
if(diff[i] == 0 || diff[i] >= n)
return false;
}
return true;
}
int main()
{
int n,num[3000],i=0,difference[3000];
cout<<"Enter Number Of Elements :";
while(cin)
{
cin>>n;
while(i<n)
{
cin>>num[i];
i++;
}
for(int j=1;j<n;j++)
difference[j-1] = fabs(num[j-1]-num[j]);
if(isItJolly(difference,n))
cout<<"It is Jolly.";
else
cout<<"It is not Jolly";
}
return 0;
}

Output:





Monday, 8 March 2021

data manipulation of web.



 Regardless of your industry, data is changing the way organisations function. Structured data, or the type of information that is only readable to machines, must have a uniform structure to work correctly. To be usable by humans, the data has to be translated and manipulated so that it is cleansed and mapped so that it can provide useful insights. With an increasing amount of data being used and stored, the necessity for data manipulation becomes even more critical.

As such, we will take a look at the ins and outs of data manipulation, as well as some of the top tips of how you and your software can better organise data to extract useful insights


What is Data Manipulation?

Data manipulation refers to the process of adjusting data to make it organised and easier to read.

Data manipulation language, or DML, is a programming language that adjusts data by inserting, deleting and modifying data in a database such as to cleanse or map the data. SQL, or Structured Query Language, is a language that communicates with databases. When using SQL- data change statements for data manipulation, four functions can occur, namely:

- Select
- Update
- Insert
- Delete

These commands tell the database where to select data from and what to do with it.

Here’s how it works:

- SELECT: The select statement allows users to pull a selection from the database to work with. You tell the computer what to SELECT and FROM where.

- UPDATE: To change data that already exists, you will use the UPDATE statement. You can tell the database to update certain sets of information and the new information that should be input, either with single records or multiple records at a time.

- INSERT: You can move data from one location to another by using the INSERT statement.

- DELETE: To get rid of existing records within a table, you use the DELETE statement. You tell the system where to delete from and what files to get rid of.

Since SQL does not allow you to import or export data from outside sources, some providers can store data and give you the tools to manipulate data for your business needs.

Purpose of Data Manipulation

Data manipulation is a crucial function for business operations and optimisation. To properly use data and transform it into useful insights like analysing financial data, customer behaviour and performing trend analysis, you have to be able to work with the data in the way you need it. As such, data manipulation provides many benefits to a business, including:

- Consistent data: Having data in a consistent format allows it to be organised, read and better understood. When you take data from different sources, you may not have a unified view, but with data manipulation and commands, you can make sure that your data is consistently organised and stored.

- Project data: Being able to use historical data to project the future and provide more in-depth analysis is paramount for businesses, especially when it comes to finances. Data manipulation makes this function possible.

- Create more value from the data: Overall, being able to transform, edit, delete and insert data into a database means that you can do more with your data. By having information that stays static, it becomes useless. But, when you know how to use data to your benefit, you can have clear insights to make better business decisions.

- Remove or ignore unneeded data: Frequently, there is data that is unusable and can interfere with what matters. Unnecessary or inaccurate data should be cleaned and deleted. With data manipulation, you can quickly cleanse your records so that you can work with the information that matters.

Steps to Manipulate Data

To get started with data manipulation, you’ll want to understand the general steps and order of operations.

1. To begin, you’ll need a database, which is created from your data sources.
2. You then need to cleanse your data, with data manipulation, you can clean, rearrange and restructure data.
3. Next, import and build a database that you will work from.
4. You can combine, merge and delete information
5. Then analyse the data, to make all of this information come to life, and glean useful insights.

How to Get Started? Excel Tips for Basic Data Manipulation

Some many essential tips and tricks allow you to get the most out of your data, even when it’s in Microsoft Excel, for example. Some of these include:

1. Functions and formulas: You can use essential math functions to make your numbers mean more. By merely writing essential math functions into the bar in Excel, you can add, subtract, multiply and divide data to see immediate results.

2. Autofill function: In the same vein, if you want to run an equation across multiple cells, but don’t want to keep retyping it, you can drag your mouse to the bottom right corner of the cell and drag it downwards to apply the same formula to multiple rows at a time.

3. Filter and sorting: With large datasets, it’s useful to be able to filter and sort information based on your needs. You can use this feature to save time in analysing data.

4. Remove duplicates: Duplicate data can affect your analysis. As such, you can remove duplicates by utilising the “remove duplicate” function on a spreadsheet once you’ve selected the data you want to work with.

5. Merging, Separating, creating and combining columns: To further organise data, you can connect, merge or separate columns and sheets of data.

Say Goodbye to Manual Data Entry

How to Improve? Advanced Tips for Data Manipulation

The best and most efficient way to manage data manipulation is through software programs that offer advanced and automatic data manipulation features. Data automation tools like Solvexia offer benefits like automatically cleanse, map, validate, calculate, and store data with a live feed so you can say goodbye to manual data entry and low-value repetitive tasks. Additionally, with automation, reports can be generated and sent to specific people with no human interference. These reports help to run analysis, predict trends and create forecast models efficiently. Furthermore, with a robust system, all data is securely stored and allows for audit trails for governance and accessible data for collaboration.

Data manipulation within the finance industry can save a ton of time. Rather than having to copy-paste data from invoices or expense reports, software systems can handle data migration and reduce the level of human error, as a primary example.

The Bottom Line

Data comes in many forms and is needed for business leaders to be able to make decisions. From marketing to sales, accounting to customer service, data is best utilised when it can be manipulated for any relevant purpose. Proper data analysis relies on the ability to perform data manipulation, which involves rearranging, sorting, editing and moving data around.

There are many different ways to execute data manipulation, from basic operations in Microsoft Excel spreadsheets to SQL to software programs like SolveXia, that can do the work for you by executing commands. Starting with data collection to data organisation, you’ll want to be able to take data from various sources and combine it to get the insights you need.


By.Dnyaneshwar chakotkar.

Monday, 15 February 2021

python snake game .....


 import pygame

pygame.init()

dis=pygame.display.set_mode((400,300))

pygame.display.update()

pygame.quit()

quit()

import pygame

pygame.init()

dis=pygame.display.set_mode((400,300))

pygame.display.update()

pygame.display.set_caption('Snake game by Edureka')

game_over=False

while not game_over:

    for event in pygame.event.get():

        print(event)   #prints out all the actions that take place on the screen

 

pygame.quit()

quit()

import pygame

pygame.init()

dis=pygame.display.set_mode((400,300))

pygame.display.update()

pygame.display.set_caption('Snake game by Edureka')

game_over=False

while not game_over:

    for event in pygame.event.get():

        if event.type==pygame.QUIT:

            game_over=True

 

pygame.quit()

quit()

import pygame

pygame.init()

dis=pygame.display.set_mode((400,300))

 

pygame.display.set_caption('Snake game by Edureka')

 

blue=(0,0,255)

red=(255,0,0)

 

game_over=False

while not game_over:

    for event in pygame.event.get():

        if event.type==pygame.QUIT:

            game_over=True

    pygame.draw.rect(dis,blue,[200,150,10,10])

    pygame.display.update()

pygame.quit()

quit()

import pygame

 

pygame.init()

 

white = (255, 255, 255)

black = (0, 0, 0)

red = (255, 0, 0)

 

dis = pygame.display.set_mode((800, 600))

pygame.display.set_caption('Snake Game by Edureka')

 

game_over = False

 

x1 = 300

y1 = 300

 

x1_change = 0       

y1_change = 0

 

clock = pygame.time.Clock()

 

while not game_over:

    for event in pygame.event.get():

        if event.type == pygame.QUIT:

            game_over = True

        if event.type == pygame.KEYDOWN:

            if event.key == pygame.K_LEFT:

                x1_change = -10

                y1_change = 0

            elif event.key == pygame.K_RIGHT:

                x1_change = 10

                y1_change = 0

            elif event.key == pygame.K_UP:

                y1_change = -10

                x1_change = 0

            elif event.key == pygame.K_DOWN:

                y1_change = 10

                x1_change = 0

 

    x1 += x1_change

    y1 += y1_change

    dis.fill(white)

    pygame.draw.rect(dis, black, [x1, y1, 10, 10])

 

    pygame.display.update()

 

    clock.tick(30)

 

pygame.quit()

quit()

import pygame

import time

pygame.init()

 

white = (255, 255, 255)

black = (0, 0, 0)

red = (255, 0, 0)

 

dis_width = 800

dis_height  = 600

dis = pygame.display.set_mode((dis_width, dis_width))

pygame.display.set_caption('Snake Game by Edureka')

 

game_over = False

 

x1 = dis_width/2

y1 = dis_height/2

 

snake_block=10

 

x1_change = 0

y1_change = 0

 

clock = pygame.time.Clock()

snake_speed=30

 

font_style = pygame.font.SysFont(None, 50)

 

def message(msg,color):

    mesg = font_style.render(msg, True, color)

    dis.blit(mesg, [dis_width/2, dis_height/2])

 

while not game_over:

    for event in pygame.event.get():

        if event.type == pygame.QUIT:

            game_over = True

        if event.type == pygame.KEYDOWN:

            if event.key == pygame.K_LEFT:

                x1_change = -snake_block

                y1_change = 0

            elif event.key == pygame.K_RIGHT:

                x1_change = snake_block

                y1_change = 0

            elif event.key == pygame.K_UP:

                y1_change = -snake_block

                x1_change = 0

            elif event.key == pygame.K_DOWN:

                y1_change = snake_block

                x1_change = 0

 

    if x1 >= dis_width or x1 < 0 or y1 >= dis_height or y1 < 0:

        game_over = True

 

    x1 += x1_change

    y1 += y1_change

    dis.fill(white)

    pygame.draw.rect(dis, black, [x1, y1, snake_block, snake_block])

 

    pygame.display.update()

 

    clock.tick(snake_speed)

 

message("You lost",red)

pygame.display.update()

time.sleep(2)

 

pygame.quit()

quit()

import pygame

import time

import random

 

pygame.init()

 

white = (255, 255, 255)

black = (0, 0, 0)

red = (255, 0, 0)

blue = (0, 0, 255)

 

dis_width = 800

dis_height = 600

 

dis = pygame.display.set_mode((dis_width, dis_height))

pygame.display.set_caption('Snake Game by Edureka')

 

clock = pygame.time.Clock()

 

snake_block = 10

snake_speed = 30

 

font_style = pygame.font.SysFont(None, 30)

 

 

def message(msg, color):

    mesg = font_style.render(msg, True, color)

    dis.blit(mesg, [dis_width/3, dis_height/3])

 

 

def gameLoop():  # creating a function

    game_over = False

    game_close = False

 

    x1 = dis_width / 2

    y1 = dis_height / 2

 

    x1_change = 0

    y1_change = 0

 

    foodx = round(random.randrange(0, dis_width - snake_block) / 10.0) * 10.0

    foody = round(random.randrange(0, dis_width - snake_block) / 10.0) * 10.0

 

    while not game_over:

 

        while game_close == True:

            dis.fill(white)

            message("You Lost! Press Q-Quit or C-Play Again", red)

            pygame.display.update()

 

            for event in pygame.event.get():

                if event.type == pygame.KEYDOWN:

                    if event.key == pygame.K_q:

                        game_over = True

                        game_close = False

                    if event.key == pygame.K_c:

                        gameLoop()

 

        for event in pygame.event.get():

            if event.type == pygame.QUIT:

                game_over = True

            if event.type == pygame.KEYDOWN:

                if event.key == pygame.K_LEFT:

                    x1_change = -snake_block

                    y1_change = 0

                elif event.key == pygame.K_RIGHT:

                    x1_change = snake_block

                    y1_change = 0

                elif event.key == pygame.K_UP:

                    y1_change = -snake_block

                    x1_change = 0

                elif event.key == pygame.K_DOWN:

                    y1_change = snake_block

                    x1_change = 0

 

        if x1 >= dis_width or x1 < 0 or y1 >= dis_height or y1 < 0:

            game_close = True

 

        x1 += x1_change

        y1 += y1_change

        dis.fill(white)

        pygame.draw.rect(dis, blue, [foodx, foody, snake_block, snake_block])

        pygame.draw.rect(dis, black, [x1, y1, snake_block, snake_block])

        pygame.display.update()

 

        if x1 == foodx and y1 == foody:

            print("Yummy!!")

        clock.tick(snake_speed)

 

    pygame.quit()

    quit()

 

 

gameLoop()

import pygame

import time

import random

 

pygame.init()

 

white = (255, 255, 255)

yellow = (255, 255, 102)

black = (0, 0, 0)

red = (213, 50, 80)

green = (0, 255, 0)

blue = (50, 153, 213)

 

dis_width = 600

dis_height = 400

 

dis = pygame.display.set_mode((dis_width, dis_height))

pygame.display.set_caption('Snake Game by Edureka')

 

clock = pygame.time.Clock()

 

snake_block = 10

snake_speed = 15

 

font_style = pygame.font.SysFont("bahnschrift", 25)

score_font = pygame.font.SysFont("comicsansms", 35)

 

def our_snake(snake_block, snake_list):

    for x in snake_list:

        pygame.draw.rect(dis, black, [x[0], x[1], snake_block, snake_block])

 

 

def message(msg, color):

    mesg = font_style.render(msg, True, color)

    dis.blit(mesg, [dis_width / 6, dis_height / 3])

 

 

def gameLoop():

    game_over = False

    game_close = False

 

    x1 = dis_width / 2

    y1 = dis_height / 2

 

    x1_change = 0

    y1_change = 0

 

    snake_List = []

    Length_of_snake = 1

 

    foodx = round(random.randrange(0, dis_width - snake_block) / 10.0) * 10.0

    foody = round(random.randrange(0, dis_height - snake_block) / 10.0) * 10.0

 

    while not game_over:

 

        while game_close == True:

            dis.fill(blue)

            message("You Lost! Press C-Play Again or Q-Quit", red)

 

            pygame.display.update()

 

            for event in pygame.event.get():

                if event.type == pygame.KEYDOWN:

                    if event.key == pygame.K_q:

                        game_over = True

                        game_close = False

                    if event.key == pygame.K_c:

                        gameLoop()

 

        for event in pygame.event.get():

            if event.type == pygame.QUIT:

                game_over = True

            if event.type == pygame.KEYDOWN:

                if event.key == pygame.K_LEFT:

                    x1_change = -snake_block

                    y1_change = 0

                elif event.key == pygame.K_RIGHT:

                    x1_change = snake_block

                    y1_change = 0

                elif event.key == pygame.K_UP:

                    y1_change = -snake_block

                    x1_change = 0

                elif event.key == pygame.K_DOWN:

                    y1_change = snake_block

                    x1_change = 0

 

        if x1 >= dis_width or x1 < 0 or y1 >= dis_height or y1 < 0:

            game_close = True

        x1 += x1_change

        y1 += y1_change

        dis.fill(blue)

        pygame.draw.rect(dis, green, [foodx, foody, snake_block, snake_block])

        snake_Head = []

        snake_Head.append(x1)

        snake_Head.append(y1)

        snake_List.append(snake_Head)

        if len(snake_List) > Length_of_snake:

            del snake_List[0]

 

        for x in snake_List[:-1]:

            if x == snake_Head:

                game_close = True

 

        our_snake(snake_block, snake_List)

 

 

        pygame.display.update()

 

        if x1 == foodx and y1 == foody:

            foodx = round(random.randrange(0, dis_width - snake_block) / 10.0) * 10.0

            foody = round(random.randrange(0, dis_height - snake_block) / 10.0) * 10.0

            Length_of_snake += 1

 

        clock.tick(snake_speed)

 

    pygame.quit()

    quit()

 

 

gameLoop()


Tuesday, 22 December 2020

function overloading

 


# include<iostream>

using namespace std;

int area(int side)
{
 return side*side;
}

int area(int l , int b)
{
 return l*b;
}

int main()
{

        int (*p1)(int);
        int (*p2)(int,int);

        p1=area;
        p2=area;

        cout<<"Address of area(int)="<<p1<<endl;
        cout<<"Address of area(int,int)="<<p2<<endl;

        cout<<"\n";

        cout<<"Invoking area(int) via p1 "<<p1(20)<<endl;
        cout<<"Invoking area(int,int) via p2 "<<p2(10,20);

        return 0;
}



Hierarchical Inheritance Example.


👇👆👆👆👆👇👇👇👇👇


#include<iostream>


using namespace std;


class Shape

{

protected:

 float width, height;


public:

 void set_data (float a, float b)

 {

  width = a;

  height = b;

 }

};


//inheriting Shape class

class Rectangle: public Shape

{

public:

 float area ()

 {

  return (width * height);

 }

};


//inheriting Shape class

class Triangle: public Shape

{

    public:

        float area ()

        {

            return (width * height / 2);

        }

};


int main ()

{

 Rectangle rect;

 Triangle tri;


 rect.set_data (5,3);

 tri.set_data (2,5);


 cout <<"Area of Rectangle : " <<rect.area() << endl;

 cout <<"Area of Triangle : "<< tri.area() << endl;


 return 0;

}


 

Hybrid Inheritance Example.

 

 

#include<iostream>

using namespace std;

class A
{
    public:
        int l;
        void len()
        {
           cout<<"Lenght : ";
           cin>>l;
        }
};

class B : public A
{
    public:
        int b,c;
       void l_into_b()
       {
           len();
           cout<<"Breadth : ";
           cin>>b;
           c=b*l;
       }
};

class C
{
    public:
        int h;
        void height()
        {
           cout<<"Height : ";
           cin>>h;
        }
};

//Hybrid Inheritance Level
class D : public B , public C
{
    public:
        int res;
        void result()
        {
           l_into_b();
           height();
           res=h*c;

           cout<<"\n";
           cout<<endl<<"Result (l*b*h) : "<<res;
        }
};

int main()
{
    D dObj;
    dObj.result();

    return 0;
}



Merge singly linked list.


#include <iostream>
#include <cstdlib>

using namespace std;

typedef struct linked_list
{
    int data;
    struct linked_list *next;
}
Linked_list;

//for adding node
int add_node(Linked_list **head, int d)
{
    Linked_list *l = new Linked_list;
    if(l == NULL) return 0;

    Linked_list *t = *head;
    l->data = d;
    l->next = NULL;

    if(*head == NULL)
    {
        *head = l;
        return 1;
    }

    while(t->next != NULL)
    {
        t = t->next;
    }

    t->next = l;

    return 1;
}

//print the value which are there in linked list
void print_list(Linked_list *head)
{
    while(head != NULL)
    {
        cout << head->data << " ";
        head = head->next;
    }
    cout << endl;
}

void del_list(Linked_list *head)
{
    while(head != NULL)
    {
        Linked_list *t = head ->next;
        delete head;
        head = t;
    }
}

Linked_list * merge_list(Linked_list *l1, Linked_list *l2)
{
    Linked_list *h = l1, *r = l1, t;

    if(l1 == NULL)
    {
        return l2;
    }

    if(l2 == NULL)
    {
        return l1;
    }

    if(l1->data < l2->data)
    {
        h = r = l1;
        l1 = l1->next;
    }
    else
    {
        h = r = l2;
        l2 = l2->next;
    }

    while(l1->next != NULL && l2->next != NULL)
    {
        if(l1->data < l2->data)
        {
            r->next = l1;
            l1 = l1->next;
            r = r->next;
        }
        else
        {
            r->next = l2;
            l2 = l2->next;
            r = r->next;
        }
    }

    if(l1->next != NULL)
    {
        r->next = l1;
    }

    if(l2->next != NULL)
    {
        r->next = l2;
    }

    return h;
}

//declaration of main method
int main(int argc, char* argv[])
{
    Linked_list *l1 = NULL;
    Linked_list *l2 = NULL;

    for(int i = 0; i < 10; i ++)
    {
        add_node(&l1, i * 3);
    }

    print_list(l1);//it will print first linked list

    for(int i = 0; i < 10; i ++)
    {
        add_node(&l2, i * 7);
    }

    print_list(l2); //it will print 2nd linked list

    Linked_list *h = merge_list(l1, l2);

    print_list(h);

    del_list(h);

 return 0;
}








 

method of overloading

 

//program to show how method overloading works


# include<iostream>


using namespace std;


//area method with one parameter

int area(int side)

{

 return side*side;

}


//area method with two parameter

int area(int l , int b)

{

 return l*b;

}


int main()

{


 int (*para1)(int);

 int (*para2)(int,int);


 para1=area;

 para2=area;


 cout<<"Address of area(int) : "<<(unsigned int)para1<<endl;

 cout<<"Address of area(int,int) : "<<(unsigned int)para2<<endl;


 cout<<"Invoking area(int) via para1 : "<<para1(20)<<endl;

 cout<<"Invoking area(int,int) via para2 : "<<para2(10,20);

}



Monday, 21 December 2020

Minus Operator overloading

 


#include<iostream>


using namespace std;


class MinusOperatorOverloading

{

    int x,y,z;


    public:

    void get_data(int a,int b,int c)

    {

        x = a;

        y = b;

        z = c;

    }


    void operator -()

    {

        x = x - 10;

        y = y - 10;

        z = z - 10;

    }


    void display()

    {

        cout<<"\nx: "<<x;

        cout<<"\ny: "<<y;

        cout<<"\nz: "<<z;

    }

};


int main()

{

    MinusOperatorOverloading oo;

    oo.get_data(53,73,93);

    cout<<"Before overloading:";

    oo.display();


    -oo;


    cout<<"\n\n";

    cout<<"After overloading:";


    oo.display();


    return 0;

}




Multilevel Inheritance Example.


 Multilevel Inheritance Example. 


#include<iostream>
#include<string.h>

using namespace std;

class student
{
    private:
      int rl;
      char nm[20];

    public:
       void read();
       void display();
};

class marks : public student
{
    protected:
      int s1;
      int s2;
      int s3;

    public:
       void getmarks();
       void putmarks();
};

class result : public marks
{
    private:
      int t;
      float p;
      char div[10];

    public:
       void process();
       void printresult();
};

void student::read()
{
    cout<<"Enter Roll no. : ";
    cin>>rl;

    cout<<"Enter Name : ";
    cin>>nm;
}

void student:: display()
{
    cout <<"\nRoll no. : "<<rl<<endl;
    cout<<"Name : "<<nm<<endl;

    cout<<"\n";
}

void marks ::getmarks()
{
    cout<<"Enter marks for 3  subjects : "<<endl;
    cin>>s1>>s2>>s3;
}

void marks ::putmarks()
{
    cout<<"Subject 1 :"<<s1<<endl;
    cout<<"Subject 2 : "<<s2<<endl;
    cout<<"Subject 3 : "<<s3<<endl;
}

void result::process()
{
    t= s1+s2+s3;
    p = t/3.0;
    p>=60?strcpy(div,"First"):p>=50?strcpy(div, "Second"): strcpy(div,"Third");
}

void result::printresult()
{
    cout<<"Total = "<<t<<endl;

    cout<<"\n";

    cout<<"Percentage  = "<<p<<endl;
    cout<<"Division = "<<div<<endl;
}

int main()
{
    result x;

    x.read();
    x.getmarks();
    x.process();
    x.display();
    x.putmarks();
    x.printresult();

    return 0;
}



. Multiple Inheritance Example.

 

#include <iostream>


using namespace std;


class Area

{

    public:

    float area_calc(float l,float b)

    {

        return l*b;

    }

};


class Perimeter

{

    public:

    float peri_calc(float l,float b)

    {

        return 2*(l+b);

    }

};


//Rectangle class is derived from classes Area and Perimeter.

class Rectangle : private Area, private Perimeter

{

    private:

    float length, breadth;


    public:

    Rectangle() : length(0.0), breadth(0.0) { }


    void get_data( )

    {

        cout<<"Enter length: ";

        cin>>length;


        cout<<"Enter breadth: ";

        cin>>breadth;

    }


    float area_calc()

    {

        //Calls area_calc() of class Area and returns it.

        return Area::area_calc(length,breadth);

    }


    float peri_calc()

    {

        //Calls peri_calc() function of class Perimeter and returns it.

        return Perimeter::peri_calc(length,breadth);

    }

};


int main()

{

    Rectangle r;

    r.get_data();


    cout<<"\n\n";


    cout<<"Area = "<<r.area_calc();

    cout<<"\nPerimeter = "<<r.peri_calc();


    return 0;

}





Arithematic ooprations using class

 

dnyaneshwarchakotkar.bogspot.com

#include <iostream>

using namespace std;


//define class

class operations

{

    //member variables

    public:

        int num1,num2;


    //member function or methods

    public:

       void add()

       {

           cout<<"enter two number for addition : ";

           cin>>num1>>num2;

           cout<<"addition = "<<num1+num2;

           cout<<"\n";

       }


        void sub()

       {

           cout<<"enter two number for subtraction : ";

           cin>>num1>>num2;

           cout<<"addition = "<<num1-num2;

           cout<<"\n";

       }


        void mul()

       {

           cout<<"enter two number for multiplication : ";

           cin>>num1>>num2;

           cout<<"addition = "<<num1*num2;

           cout<<"\n";

       }


        void div()

       {

           cout<<"enter two number for division : ";

           cin>>num1>>num2;

           cout<<"addition = "<<(float)num1/num2;

           cout<<"\n";

       }

};

 int main()

 {

     //creation of object

      operations op1;

      op1.add();

      op1.sub();

      op1.mul();

      op1.div();

      return 0;

 }






if you have more source code in simle way join this blog also do like and get the subsciption of tha blog on dnyaneshwarchakotkar.blolgspot.comm



also share the blog link to your friebnd for study,.....!!!!!


Search This Blog

Contact Form

Name

Email *

Message *

Popular Posts