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");
}
}

Write program to implement a queue class with required operations/ functions.

#include <iostream.h>
#define MAX 10
class queue
{
private:
int arr[ MAX ];
int front,
rear;
public:
queue( )
{
front = -1;
rear = -1;
}
void addq(int it)
{
int item=it;
if( rear == MAX - 1 )
{
cout << endl << "Queue is full";
return;
}
rear++;
arr[ rear ] = item;
if( front == -1 )
front = 0;
}
int delq( )
{
int data;
if( front == -1 )
{
cout << endl << "Queue is empty";
return NULL;
}
data = arr[ front ];
if( front == rear )
front = rear = -1;
else
front++;
return data;
}
};
void main( )
{

queue a;
a.addq( 11 );
a.addq( 12 );
a.addq( 13 );
a.addq( 14 );
a.addq( 15 );
a.addq( 16 );
a.addq( 17 );
a.addq( 18 );
a.addq( 19 );
a.addq( 20 );
a.addq( 21 );
int i = a.delq( );
cout << endl << "Item deleted=" << i;
i = a.delq( );
cout << endl << "Item deleted=" << i;
i = a.delq( );
cout << endl << "Item deleted=" << i;
}

Sunday 3 May 2020

Program to display a matrix.

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

The annual examination result of 50 students in a class is tabulated in a Single Dimensional Array (SDA) is as follows:

Write a program to read the data, calculate and display the following:
(a) Average marks obtained by each student.
(b) Print the roll number and the average marks of the students whose average is above.
80.
(c) Print the roll number and the average marks of the students whose average is below
40.


import java.util.Scanner;
public class ATS
{
public static void main(String[]args)
{
final int TOTAL_STUDENTS = 50;
Scanner in = new Scanner(System.in);
int rollNo[] = new int[TOTAL_STUDENTS];
int sA[] = new int[TOTAL_STUDENTS];
int sB[] = new int[TOTAL_STUDENTS];
int sC[] = new int[TOTAL_STUDENTS];
double avg[] = new double[TOTAL_STUDENTS];
for (int i = 0; i < TOTAL_STUDENTS; i++)
{
System.out.println("Enter student " + (i+1) + " details:");
System.out.print("Roll No: ");
rollNo[i] = in.nextInt();
System.out.print("Subject A Marks: ");
sA[i] = in.nextInt();
System.out.print("Subject B Marks: ");
sB[i] = in.nextInt();
System.out.print("Subject C Marks: ");
sC[i] = in.nextInt();
avg[i] = (sA[i] + sB[i] + sC[i]) / 3.0;
}
System.out.println("\nRoll No\tAverage Marks");
for (int i = 0; i < TOTAL_STUDENTS; i++)
{
System.out.println(rollNo[i] + "\t" + avg[i]);
}
System.out.println("\nStudents with Average above 80:");
for (int i = 0; i < TOTAL_STUDENTS; i++)
{
if (avg[i] > 80)
System.out.println(rollNo[i] + "\t" + avg[i]);
}
System.out.println("\nStudents with Average below 40:");
for (int i = 0; i < TOTAL_STUDENTS; i++)
{
if (avg[i] < 40)
System.out.println(rollNo[i] + "\t" + avg[i]);
}
}

Write a program showing implementation of stack class having the functionality of push, pop operations.

#include<iostream.h>
#define MAX 10
class stack
{
private:
int arr[ MAX ], top;
public:
stack( )
{
top = -1;
}
void push( int item )
{
if( top == MAX - 1 )
{
cout << endl << "Stack is full";
return;
}
top++;
arr[ top ] = item;
}
int pop( )
{
if( top == -1 )
{
cout << endl << "Stack is empty";
return NULL;
}
int data = arr[ top ];
top--;
return data;
}
};
void main( )
{
stack s;
s.push( 11 );
s.push( 12 );
s.push( 13 );
s.push( 14 );
s.push( 15 );
s.push( 16 );
s.push( 17 );
s.push( 18 );
s.push( 19 );
s.push( 20 );
s.push( 21 );
int i = s.pop( );
cout << endl << "Item popped=" << i;
i = s.pop( );
cout << endl << "Item popped=" << i;
i = s.pop( );
cout << endl << "Item popped=" << i;
i = s.pop( );
cout << endl << "Item popped=" << i;
}

Friday 1 May 2020

WAP to find the maximum in an array

#include<stdio.h>
#include<conio.h>
void main()
{
int a[5],max,i;
clrscr();
printf(“enter element for the array: ”);
for(i=0;i<5;i++)
scanf(“%d”,&a[i]);
max=a[0];
for(i=1;i<5;i++)
{
if(max<a[i])
max=a[i];
}
printf(“maximum no= %d”,max);
getch();
}

Write a program to accept 10 different decimal numbers (double data type) in a Single Dimensional Array (say, A). Truncate the fractional part of each number of the array A and store their integer part in another array (say, B).

import java.util.Scanner;
public class ATS
{
public static void main(String[]args)
{
Scanner in = new Scanner(System.in);
double a[] = new double[10];
int b[] = new int[10];
System.out.println("Enter 10 decimal numbers");
for (int i = 0; i < a.length; i++)
{
a[i] = in.nextDouble();
b[i] = (int)a[i];
}
System.out.println("Truncated numbers");
for (int i = 0; i < b.length; i++)
{
System.out.print(b[i] + ", ");
}
}
}

Write a Program for reading and writing data to and from the file using command line arguments.

#include<iostream.h>
#include<fstream.h>
#include<stdlib.h>
int main(int argc, char *argv[])
{
int number[9] = {11,22,33,44,55,66,77,88,99};
if(argc!=3)
{
cout<<"argc="<<argc<<"\n";
cout<<"Error in arguments\n";
exit(1);
}
ofstream fout1, fout2;
fout1.open(argv[1]);
if(fout1.fail())
{
cout<<"Could not open the file:"
<<argv[1]<<"\n";
exit(1);
}
fout2.open(argv[2]);
if(fout2.fail())
{
cout<<"Could not open the file:"
<<argv[2]<<"\n";
exit(1);
}
for(int i=0; i<9; i++)
{
if(number[i] % 2 == 0)
fout2<<number[i]<<" ";
else
fout1<<number[i]<<" ";
}
fout1.close();
fout2.close();
ifstream fin;
char ch;
for(i=1; i<argc; i++)
{
fin.open(argv[i]);
cout<<"Contents of "<<argv[i]<<"\n";
do
{
fin.get(ch);
cout<<ch;
}while(fin);
cout<<"\n\n";
fin.close();
}
return 0;
}

How to Learn Hindi Typing in 5 Minutes



How to Learn Hindi Typing in 5 Minutes :
5 मिनिट में हिंदी टाइपिंग करना सीखे :
दोस्तों आज और अब मै आपको हिंदी टाइपिंग सीखने का आसान तरीका बताऊंगा , अब आप इस आर्टिकल को पढने के बाद फटाफट हिंदी टाइपिंग सीख पायेंगे| पहले गूगल की साईट पर ही यह व्यवस्था थी जिससे हम आसानी से हिंदी टाइपिंग कर  सकते थे, पर अब गूगल ने यह टूल वहां हटा लिया है| लेकिन आप फ़िक्र न करे हम आपकी समस्या को समझते है और आपको बातायेंगे कई आप 5 मिनिट में हिंदी टाइपिंग कैसे करें|
गूगल हिंदी इनपुट टूल ( Google Hindi Input Tool) एक ऐसा सॉफ्टवेर है जिससे हम आसानी से हिंदी टाइपिंग कर सकते है| आप निचे लिखे हुए steps को करते जाये और गूगल हिंदी इनपुट टूल ( Google Hindi Input Tool) को डाउनलोड (Download) करले|
स्टेप-१ : सबसे पहले नीचे दिए लिंक से सॉफ्टवेर को डाउनलोड करे|
(step-1) : Download the software from given Link ,





स्टेप-२ : अब इस सोफ्टवेयर को अनज़िप (unzip / extract) करले |
(step-2) : Extract the Download software ,

स्टेप-3 : अब  इस पहले सॉफ्टवेर को इन्स्टाल करले |
(Step-3): Now Install First Software

स्टेप ४: अब  इस दूसरे सॉफ्टवेर को इन्स्टाल करले |
(Step-4): Now Install Second Software


स्टेप -5 : अब आपको एक न्य icon , taskbaar में मिलेगा , उसे खोल ले |
(Step-5): Now you will find the icon in task bar.


स्टेप- ६: इसमें हिंदी गूगल इनपुट टूल को सेलेक्ट करे|
(Step-6): Now Select th Hindi Input Tools.\


स्टेप-७: अब आप किसी भी सॉफ्टवेर में हिंदी में टाइप कर सकते है|
(Step-7): Now you can type anything in the MS word or any other software of typing.


आपको यदि पोस्ट से फायदा हुआ हो या अच्छी लगी हो तो कमेंट्स जरूर करे|
धन्यवाद|

इनमे आपने सिखा कि: हिंदी टाइपिंग सीखने के लिए अब आसान तरीका, हिंदी टाइपिंग सीखने कई ट्रिक, हिंदी टाइपिंग कैसे सीखी जाती है, हिंदी में टाइपिंग कैसे करे , हिंदी टाइपिंग जल्दी कैसे सीखे




Thursday 30 April 2020

Program to show sum of 10 elements of array & show the average.

#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],i,sum=0;
float av;
clrscr();
printf(“enter elements of an aaray: ”);
for(i=0;i<10;i++)
scanf(“%d”,&a[i]);
for(i=0;i<10;i++)
sum=sum+a[i];
printf(“sum=%d”,sum);
av=sum/10;
printf(“average=%.2f”,av);
getch();
}

Write a program to accept a list of 20 integers. Sort the first 10 numbers in ascending order and next the 10 numbers in descending order by using 'Bubble Sort' technique. Finally, print the complete list of integers.

import java.util.Scanner;
public class round
{
public static void main(String[]args)
{
Scanner in = new Scanner(System.in);
int arr[] = new int[20];
System.out.println("Enter 20 numbers:");
for (int i = 0; i < arr.length; i++)
{
arr[i] = in.nextInt();
}
for (int i = 0; i < arr.length / 2 - 1; i++)
{
for (int j = 0; j < arr.length / 2 - i - 1; j++)
{
if (arr[j] > arr[j + 1])
{
int t = arr[j + 1];
arr[j + 1] = arr[j];
arr[j] = t;
}
}
}

for (int i = 0; i < arr.length / 2 - 1; i++)
{
for (int j = arr.length / 2; j < arr.length - i - 1; j++)
{
if (arr[j] < arr[j + 1])
{
int t = arr[j + 1];
arr[j + 1] = arr[j];
arr[j] = t;
}
}
}

System.out.println("\nSorted Array:");
for (int i = 0; i < arr.length; i++)
{
System.out.print(arr[i] + " ");
}
}
}

Write a program to maintain a elementary database of employees using files.

#include <fstream.h>
#include <conio.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <iomanip.h>
class group
{
private:
struct person
{
char flag;
char empcode[ 5 ];
char name[ 40 ];
int age;
float sal;
} p;
fstream file;
public:
group( );
void addrec( );
void listrec( );
void modirec( );
void delrec( );
void recallrec( );
void packrec( );
void exit( );
};
void main( )
{
char choice;
group g;
do
{
clrscr( );
gotoxy( 30, 10 );
cout << "1. Add records";
gotoxy( 30, 11 );
cout << "2. List records";
gotoxy( 30, 12 );
cout << "3. Modify records";
gotoxy( 30, 13 );
cout <<"4. Delete records";
gotoxy( 30, 14 );
cout << "5. Recall records";
gotoxy( 30, 15 );
cout << "6. Pack records";
gotoxy( 30, 16 );
cout << "0. Exit";
gotoxy( 30, 18 );
cout << "Your Choice ? ";
cin >> choice;
clrscr( );
switch( choice )
{
case '1':
g.addrec( );
break;
case '2':
g.listrec( );
break;
case '3':
g.modirec( );
break;
case '4':
g.delrec( );
break;
case '5':
g.recallrec( );
break;
case '6':
g.packrec( );
break;
case '0':
g.exit( );
break;
}
}while( choice != 0 );
}
void group::group( )
{
file.open( "emp.dat", ios::binary || ios::in || ios::out );
if( !file )
{
cout << endl << "Unable to open file";
exit( );
}
}
void group::addrec( )
{
char ch;
file.seekp( 0L, ios::end );
do
{
cout << endl << "Enter emp code, name, age & salary" << endl;
cin >> p.empcode >> p.name >> p.age >> p.sal;
p.flag = '';
file.write( ( char * )&p, sizeof( p ) );
cout << "Add another record? (Y/N)";
cin >> ch;
} while( ch == 'Y' || ch == 'Y' );
}
void group::listrec( )
{
int j = 0,a;
file.seekg( 0L, ios::beg );
while( file.read( ( char * )&p, sizeof( p ) ) )
{
if( p.flag != '*' )
{
cout <<endl << "Record#" << j++ << setw( 6 )<< p.empcode<<setw(20)<<p.name<<setw(4<<p.age<<setw(9)<< p.sal ;
}
file.clear( );
cout << endl << "Press any key......";
getch( );
}
}
void group::modirec( )
{
char code[ 5 ];
int count = 0;
long int pos;
cout << "Enter employee code: ";
cin >> code;
file.seekg( 0L, ios::beg );
while( file.read( ( char * )&p, sizeof( p ) ) )
{
if( strcmp( p.empcode, code ) == 0 )
{
cout << endl << "Enter new record" << endl;
cin >> p.empcode >> p.name >> p.age;
p.flag = '';
pos = count * sizeof( p );
file.seekp( pos, ios::beg );
file.write( ( char * )&p, sizeof( p ) );
return;
}
count++;
}
cout << endl << "No employee in file with code = " << code;
cout << endl << "Press any key .....";
getch( );
file.clear( );
}
void group::delrec( )
{
char code[ 5 ];
long int pos;
int count = 0;
cout << "Enter employee code : ";
cin >> code;
file.seekg( 0L, ios::beg );
while( file.read( ( char * )&p, sizeof( p ) ) )
{
if( strcmp( p.empcode, code ) == 0 )
{
p.flag = '*';
pos = count * sizeof( p );
file.seekp( pos, ios::beg );
file.write( ( char * )&p, sizeof( p ) );
return;
}
count++;
}
cout << endl << "No employee in file with code = " << code;
cout<<endl<<Press any key ....";
getch( );
file.clear( );
}
void group.recallrec()
{
char code[ 5 ];
long int pos;
int count = 0;
cout << "Enter employee code: ";
cin >> code;
file.seekg( 0L, ios::beg );
while( file.read( ( char * )&p, sizeof( p ) ) )
{
if( strcmp( p.empcode, code ) == 0 )
{
p.flag = '';
pos = count * sizeof( p );
file.seekp( pos, ios::beg );
file.write( ( char * )&p, sizeof( p ) );
return;
}
count++;
}
cout << endl << "No employee in file with code = " << code;
cout << endl << "Press any key ....";
file.clear( );
}
void group::packrec( )
{
ofstream outfile;
outfile.open( "TEMP", ios::out );
file.seekg( 0, ios::beg );
while( file.read( ( char * )&p, sizeof( p ) ) )
{
if( p.flag != '*' )
outfile.write((char *)&p,sizeof(p)));
}
outfile.close( );
file.close( );
remove( "EMP.dat" );
rename( "TEMP", "TEMP.dat" );
file.open( "EMP.dat", ios::binary | ios::in | ios::out | ios::nocreate );
}
void group::exit( )
{
file.close( );
}