Thursday, 7 May 2020

Program to show subtraction of 2 array into third array

#include<stdio.h>
#include<conio.h>
void main()
{
int a[5],b[5],c[5],i;
clrscr();
printf(“enter value for array a ”);
for(i=0;i<5;i++)
scanf(“%d”,&a[i]);
printf(“enter value for array b ”);
for(i=0;i<5;i++)
scanf(“%d”,&b[i]);
for(i=0;i<5;i++)
c[i]=a[i]-b[i];
printf(“subtraction”);
for(i=0;i<5;i++)
printf(“ %d ”,c[i]);
getch();
}

A Metropolitan Hotel has 5 floors and 10 rooms in each floor. The names of the visitors are entered in a Double Dimensional Array (DDA) as M[5][10].The Hotel Manager wants to know from the "Enquiry" about the position of a visitor (i.e. floor number and room number) as soon as he enters the name of the visitor. Write a program in Java to perform the above task.

import java.util.Scanner;
public class ATS
{
public static void main(String[]args)
{
Scanner in = new Scanner(System.in);
String M[][] = new String[5][10];
int i = 0, j = 0;
for (i = 0; i < 5; i++)
{
System.out.println("Enter floor " + (i + 1)+ " guest details:");
for (j = 0; j < 10; j++)
{
System.out.print("Guest in room " +(j + 1) + ": ");
M[i][j] = in.nextLine();
}
}
boolean found = false;
System.out.print("\nEnter guest name to search: ");
String guest = in.nextLine();
for (i = 0; i < 5; i++)
{
for (j = 0; j < 10; j++)
{
if (M[i][j].equals(guest))
{
found = true;
break;
}
}
if (found)
break;
}
if (found)
System.out.println(guest + " is in room number "+ (j + 1) + " on floor number " + (i + 1));
else
System.out.println(guest +" is not staying at this hotel");
}
}

Write a program implementing linked list as a class. Also Perform some required operations like inserting, deleting nodes & display the contents of entire linked list.

#include <iostream.h>
class linklist
{
struct node
{
int data;
node * link;
}*p;
public:
linklist( );
void append( int num );
void addatbeg( int num );
void addafter( int c, int num );
void del( int num );
void display( );
int count( );
~linklist( );
};
linklist::linklist( )
{
p = NULL;
}
void linklist::append( int num )
{
node * q,
* t;
if( p == NULL )
{
p = new node;
p->data = num;
p->link = NULL;
}
else
{
q = p;
while( q->link != NULL )
q = q->link;
t = new node;
t->data = num;
t->link = NULL;
q->link = t;
}
}
void linklist::addatbeg( int num )
{
node * q;
q = new node;
q->data = num;
q->link = p;
p = q;
}
void linklist::addafter( int c, int num )
{
node * q,* t;
int i;
for( i = 0, q = p; i < c; i++ )
{
q = q->link;
if( q = NULL )
{
cout << endl << "There are less than " << c << "element";
return;
}
}
t = new node;
t->data = num;
t->link = q->link;
q->link = t;
}
void linklist::del( int num )
{
node * q,* r;
q = p;
if( q->data == num )
{
p = q->link;
delete q;
return;
}
r = q;
while( q != NULL )
{
if( q->data == num )
{
r->link = q->link;
delete q;
return;
}
r = q;
q = q->link;
}
cout << endl << "Element" << num << "not found";
}
void linklist::display( )
{
node * q;
cout << endl;
for( q = p; q->link != NULL; q = q->link )
{
cout << endl << q->data;
}
int linklist::count( )
{
node * q;
int c = 0;
for( q = p; q != NULL; q = q->link )
c++;
return ( c );
}
linklist::~linklist( )
{
node * q;
if( p == NULL )
return;
while( p != NULL )
{
q = p->link;
delete p;
p = q;
}
}
void main( )
{
linklist ll;
cout << endl << "No. of elements in linked list= " << ll.count( );
ll.append( 11 );
ll.append( 22 );
ll.append( 33 );
ll.append( 44 );
ll.append( 55 );
ll.addatbeg( 100 );
ll.addatbeg( 200 );
ll.addatbeg( 300 );
ll.addafter( 3, 333 );
ll.addafter( 6, 444 );
ll.display( );
cout << endl << "No. of element in linked list =" << ll.count( );
ll.del( 300 );
ll.del( 66 );
ll.del( 0 );
ll.display( );
cout << endl << "No. of element in linked list =" << ll.count( );
}

Tuesday, 5 May 2020

Object Oriented Programming Features in Hindi

Features of C++



•Reusability- The code written in C++ for one program canbe used in another program of C++.

•Bottom-Up Approach- C++ may define functions and program data first and then integrate them together for use.

•Object Oriented Programming- C++ Provides mechanism to combine both data and the function of that data into a single unit, called object.

•Portability- Same C++ code can be compiled in almost any type of computer and operating system without any changes.

•Brevity- Code written in C++ is very short in comparison with other languages.

•Modular Programming- An application’s body in C++ can be made up of several source code files (called modules) that are compiled separately and then linked together.

•C Compatibility- Any code of C can easily be included in a C++ program without hardly making any change.

•Speed-The resulting code from a C++ compilation is very efficient, due indeed to its duality as high-level and low-level language and to the reduced size of the language itself.







Object Oriented Programming Features


-Emphasis on objects instead of problem solution

-Program developed around objects and classes.

-There are 4 basic features of object oriented programming:

1.Encapsulation
2.Abstraction
3.Inheritance
4.Polymorphism






Monday, 4 May 2020

Program to find sum of two matrices

#include<stdio.h>
#include<conio.h>
void main()
{
int a[3][2],b[3][2],c[3][2],i,j;
clrscr();
printf(“Enter value for 1 matrix: ”);
for(i=0;i<3;i++)
{
for(j=0;j<2;j++)
scanf(“%d”,&a[i][j]);
}
printf(“Enter value for 2 matrix: ”);
for(i=0;i<3;i++)
{
for(j=0;j<2;j++)
scanf(“%d”,&b[i][j]);
}
for(i=0;i<3;i++)
{
for(j=0;j<2;j++)
c[i][j]=a[i][j]+b[i][j];
}
printf(“Sum of matrix is\n”);
for(i=0;i<3;i++)
{
for(j=0;j<2;j++)
{
printf(“%d\t”,c[i][j]);
}
printf(“\n”);
}
getch();
}

Write a program to accept the year of graduation from school as an integer value from the user. Using the binary search technique on the sorted array of integers given below, output the message "Record exists" if the value input is located in the array. If not, output the message "Record does not exist".

public class ATS
{
public static void main(String[]args)
{
Scanner in = new Scanner(System.in);
int n[] = {1982, 1987, 1993, 1996, 1999, 2003, 2006, 2007, 2009, 2010};
System.out.print("Enter graduation year to search: ");
int year = in.nextInt();
int l = 0, h = n.length - 1, idx = -1;
while (l <= h)
{
int m = (l + h) / 2;
if (n[m] == year)
{
idx = m;
break;
}
else if (n[m] < year)
{
l = m + 1;
}
else
{
h = m - 1;
}
}
if (idx == -1)
System.out.println("Record does not exist");
else
System.out.println("Record exists");
}
}