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

Tuesday 28 April 2020

Program to add two number using pointers.

#include<stdio.h>
#include<conio.h>
void main()
{
int *p1,*p2,sum;
clrscr();
printf(“enter two no’s: ”);
scanf(“%d%d”,&*p1,&*p2);
sum=*p1+*p2;
printf(“sum=%d”,sum);
getch();
}

Write a program to store 20 numbers in a Single Dimensional Array (SDA). Now, display only those numbers that are perfect squares.

import java.util.Scanner;
public class ATS
{
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();
}
System.out.println("Perfect Squares are:");
for (int i = 0; i < arr.length; i++)
{
double sr = Math.sqrt(arr[i]);
if ((sr - Math.floor(sr)) == 0)
System.out.print(arr[i] + ", ");
}
}
}

Write a program to copy the contents of one file to another.

#include <fstream.h>
void main( )
{
char cource[ 67 ],
target[ 67 ];
char ch;
cout << endl << "Enter source filename";
cin >> source;
cout << endl << "Enter target filename";
cin >> target;
ifstream infile ( source );
ofstream outfile ( target );
while( infile )
{
infile.get( ch );
outfile.put( ch );
}
}

Monday 27 April 2020

Program to display series and find sum of 1+3+5+......+n.

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,sum=0;
clrscr();
printf(“Enter any no: ”);
scanf(“%d”,&n);
for(i=1;i<=n;i=i+2)
{
printf(“%d+”,i);
sum=sum+i;
}
printf("\nsum=%d",sum);
getch();
}

Write a program in Java to store 20 temperatures in °F in a Single Dimensional Array (SDA) and display all the temperatures after converting them into °C. Hint: (c/5) = (f - 32) / 9

import java.util.Scanner;
public class ATS
{
public static void main(String[]args)
{
Scanner in = new Scanner(System.in);
double arr[] = new double[20];
System.out.println("Enter 20 temperatures in degree Fahrenheit");
for (int i = 0; i < arr.length; i++)
{
arr[i] = in.nextDouble();
}
System.out.println("Temperatures in degree Celsius");
for (int i = 0; i < arr.length; i++)
{
double tc = 5 * ((arr[i] - 32) / 9);
System.out.println(tc);

}
}
}

Write a program showing data conversion between objects of different classes and conversion routine should reside in destination class.

#include <iostream.h>
#include <string.h>
#include <stdlib.h>
class dmy
{
int day,mth,yr;
public:
dmy( )
{
day = mth, yr = 0;
}
dmy( int d, int m, int y )
{
day = d;
mth = m;
yr = y;
}
int getday( )
{
return ( day );
}
int getmth( )
{
return ( mth );
}
int getyr( )
{
return ( yr );
}
void displaydata( )
{
cout << day << "\t" << mth << "\t" << yr;
}
};
class date
{
private:
char dt[ 9 ];
public:
date( )
{
dt[ 0 ] = '\0';
}
date( char * s )
{
strcpy( dt, s );

}
void displaydata( )
{
cout << dt;
}
date( dmy t )
{
int d = t.getday( );
int m = t.getmth( );
int y = t.getyr( );
char temp[ 3 ];
itoa( d, dt, 10 );
strcat( dt, "\t" );
itoa( m, temp, 10 );
strcat( dt, temp );
strcat( dt, "/" );
itoa( y, temp, 10 );
strcat( dt, temp );
}
} ;
void main( )
{
date d1;
dmy d2 ( 17, 11, 94 );
d1 = d2;
cout << endl << "d1=";
d1.displaydata( );
cout << endl << "d2=";
d2.displaydata( );
}

Sunday 26 April 2020

Program to print Fibonacci series up to 100.

#include<stdio.h>
#include<conio.h>
void main()
{
int a=1,b=1,c=0,i;
clrscr();
printf("%d\t%d\t",a,b);
for(i=0;i<=10;i++)
{
c=a+b;
if(c<100)
{
printf("%d\t",c);
}
a=b;
b=c;
}
getch();
}

Write a program in Java to store 20 numbers in a Single Dimensional Array (SDA). Display the numbers which are prime.

import java.util.Scanner;
public class ATS
{
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();
}
System.out.println("Prime Numbers:");
for (int i = 0; i < arr.length; i++)
{
if (arr[i] == 1)
continue;
boolean isPrime = true;
for (int j = 2; j <= arr[i] / 2; j++)
{
if (arr[i] % j == 0)
{
isPrime = false;
break;
}

}
if (isPrime)
System.out.print(arr[i] + ", ");

}
}
}

write a program to show conversion from string to int and vice-versa.

#include<iostream.h>
#include<stdlib.h>
#include<string.h>
class string
{
private:
char str[ 20 ];
public:
string( )
{
str[ 0 ] = '\0';
}
string( char * s )
{
strcpy( str, s );
}
string( int a )
{
itoa( a, str, 10 );
}
operator int( )
{
int i = 0,l,ss = 0,k = 1;
l = strlen( str ) - 1;
while( l >= 0 )
{
ss = ss + ( str[ l ] - 48 ) * k;
l--;
k *= 10;
}
return ( ss );
}
void displaydata( )
{
cout << str;
}
};
void main( )
{
string s1 = 123;
cout << endl << "s1=";
s1.displaydata( );
s1 = 150;
cout << endl << "s1=";
s1.displaydata( );
string s2 ( "123" );
int i = int( s2 );
cout << endl << "i=" << i;
string s3 ( "456" );
i = s3;
cout << endl << "i=" << i;
}

Saturday 25 April 2020

Program to print following sequence


*
***

*****

#include<stdio.h>
void main()
{
int i,j,k;
clrscr();
for(i=1;i<=3;i++)
{
for(j=3;j>=i;j--)
printf(“ ”);
{
for(k=1;k<=i*2-1;k++)
printf(“*”);
}
printf(“\n”);
}
getch();
}

Write a program to input the names and marks of the students in the subject. Calculate and display:

(a) The subject average marks (subject average marks = subject total/50).
(b) The highest marks in the subject and the name of the student. (The maximum marks
in the subject are 100.)


import java.util.Scanner;
public class ATS
{
public static void main(String[]args)
{
final int TOTAL_STUDENTS = 50;
Scanner in = new Scanner(System.in);
String name[] = new String[TOTAL_STUDENTS];
int marks[] = new int[TOTAL_STUDENTS];
int total = 0;
for (int i = 0; i < name.length; i++)
{
System.out.print("Enter name of student " + (i+1) + ": ");
name[i] = in.nextLine();
System.out.print("Enter marks of student " + (i+1) + ": ");
marks[i] = in.nextInt();
total += marks[i];
in.nextLine();
}
double avg = (double)total / TOTAL_STUDENTS;
System.out.println("Subject Average Marks = " + avg);
int hIdx = 0;
for (int i = 1; i < marks.length; i++)
{
if (marks[i] > marks[hIdx])
hIdx = i;
}
System.out.println("Highest Marks = " + marks[hIdx]);
System.out.println("Name = " + name[hIdx]);
}
}

Write a program to design a class representing the information regarding digital library (books, tape: book & tape should be separate classes having the base class as media ). The class should have the functionality for adding new item, issuing, deposit etc. the program should use the runtime polymorphism.

#include<iostream.h>
#include<string.h>
class media
{
protected:
char title[50];
float price;
public:
media(char *s, float a)
{
strcpy(title, s);
price = a;
}
virtual void display(){}
};
class book : public media
{
int pages;
public:
book(char *s, float a, int p) : media(s,a)
{
pages = p;
}
void display();
};
class tape : public media
{
float time;
public:
tape(char * s, float a, float t):media(s,a)
{
time =t;
}
void display();
};
void book ::display()
{
cout<<"\n Title:"<<title;
cout<<"\n Pages:"<<pages;
cout<<"\n Price:"<<price;
}
void tape ::display ()
{
cout<<"\n Title:"<<title;
cout<<"\n Play Time:"<<time<<"mins";
cout<<"\n Price:"<<price;
}
int main()
{
char * title = new char[30];
float price, time;
int pages;
cout<<"\n Enter Book Details \n";
cout<<"\n Title:";
cin>>title;
cout<<"\n Price:";
cin>>price;
cout<<"\n Pages:";
cin>>pages;
book book1(title, price, pages);
cout<<"\n Enter Tape Details";
cout<<"\n Title:";
cin>>title;
cout<<"\n Price:";
cin>>price;
cout<<"\n Play Times(mins):";
cin>>time;
tape tape1(title, price, time);
media* list[2];
list[0] = &book1;
list[1] = &tape1;
cout<<"\n Media Details";
cout<<"\n..............Book.....";
list[0]->display ();
cout<<"\n..............Tape.....";
list[1]->display ();
return 0;
}

Friday 24 April 2020

Print the following star sequence


*
**
***
****
*****

#include<stdio.h> 
#include<conio.h> 
void main()
{
int i,j,k;
clrscr(); 
for(i=1;i<=5;i++)
{
for(j=5;j>=i;j--)
printf(“ ”); 
for(k=1;k<=i;k++) 
printf(“*”);
printf(“\n”);
}
getch();
}

To get promotion in a Science stream, a student must pass in English and should pass in any of the two subjects (i.e.; Physics, Chemistry or Maths). The passing mark in each subject is 35. Write a program in a Single Dimension Array to accept the roll numbers and marks secured in the subjects for all the students. The program should check and display the roll numbers along with a message whether "Promotion is Granted" or "Promotion is not Granted". Assume that there are 40 students in the class.

import java.util.*;
public class ATS
{
public static void main(String[]args)
{
Scanner in = new Scanner(System.in);
int studentDetails[] = new int[200];
System.out.println("Enter student details");
for (int i = 0, idx = 1; i < 200; i = i + 5, idx++)
{
System.out.print("Student " + idx + " roll number: ");
studentDetails[i] = in.nextInt();
System.out.print("Student " + idx + " English Marks: ");
studentDetails[i+1] = in.nextInt();
System.out.print("Student " + idx + " Maths Marks: ");
studentDetails[i+2] = in.nextInt();
System.out.print("Student " + idx + " Physics Marks: ");
studentDetails[i+3] = in.nextInt();
System.out.print("Student " + idx + " Chemistry Marks: ");
studentDetails[i+4] = in.nextInt();
}
for (int i = 0; i < 200; i = i + 5)
{
System.out.println("Roll No: " + studentDetails[i]);
if (studentDetails[i+1] > 34 &&((studentDetails[i+2] > 34 && studentDetails[i+3] > 34) ||(studentDetails[i+2] > 34 && studentDetails[i+4] > 34) ||(studentDetails[i+3] > 34 && studentDetails[i+4] > 34)))
{
System.out.println("Promotion is granted.");
}
else
{
System.out.println("Promotion is not granted.");
}
}
}
}

Write a Program to design a stuent class representing student roll no. and a test class (derived class of student) representing the scores of the student in various subjects and sports class representing the score in sports. The sports and test class should be inherited by a result class having the functionality to add the scores and display the final result for a student.



#include<iostream.h>
class student
{
protected:
int roll_number;
public:
void get_number(int a)
{
roll_number = a;
}
void put_number(void)
{
cout<<"Roll No:"<<roll_number<<"\n";
}
};
class test : public student
{
protected:
float part1, part2;
public:
void get_marks(float x, float y)
{
part1 = x;
part2 = y;
}
void put_marks(void)
{
cout<<"Marks obtained"<<"\n"<<"part1 ="<<part1<<"\n"<<"part2 ="<<part2<<"\n";
}
};
class sports
{
protected:
float score;
public:
void get_score(float s)
{
score = s;
}
void put_score(void)
{
cout<<"Sports wt:"<<score<<"\n\n";
}
};
class result : public test, public sports
{
float total;
public:
void display(void);
};
void result ::display(void)
{
total = part1 + part2 + score;
put_number();
put_marks();
put_score();
cout<<"Total Score:"<<total<<"\n";
}
int main()
{
result student_1;
student_1.get_number (1234);
student_1.get_marks (27.5, 33.0);
student_1.get_score (6.0);
student_1.display ();
return 0;
}

Thursday 23 April 2020

Program to display arithmetic operator using switch case.

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,n,s,m,su,d;
clrscr();
printf(“enter two no’s : ”);
scanf(“%d%d”,&a,&b);
printf(“enter 1 for sum\n2 for multiply\n3for subtraction\n4 for division: ”);
scanf(“%d”,&n);
switch(n)
{
case 1:
s=a+b; printf(“sum=%d”,s);
break;
case 2:
m=a*b; printf(“multiply=%d”,m);
break;
case 3:
su=a-b; printf(“subtraction=%d”,su);
break;
case 4:
d=a/b; printf(“divission=%d”,d);
break;
default:
printf(“wrong input”);
break;
}
getch();
}

Display the following pattern

A*B*C*D*E*
A*B*C*D*
A*B*C*
A*B*
A*

public class ATS
{
public static void main(String[]args)
{
for(int i = 69; i >= 65; i--)
{
for (int j = 65; j <= i; j++)
{
System.out.print((char)j + "*");
}
System.out.println();
}
}
}

Write a Program illustrating how the constructors are implemented and the order in which they are called when the classes are inherited. Use three classes named alpha, beta, gamma such that alpha,beta are base class and gamma is derived class inheriting alpha & beta

#include<iostream.h>
#include<conio.h>
class alpha
{
int x;
public:
alpha(int i)
{
x = i;
cout<<"alpha initialized\n";
}
void show_x(void)
{
cout<<"x="<<x<<"\n";
}
};
class beta
{
float y;
public:
beta(float j)
{
y=j;
cout<<"beta initialized\n";
}
void show_y(void)
{
cout<<"y= "<<y<<"\n";
}
};
class gamma : public beta, public alpha
{
int m,n;
public:
gamma(int a, float b, int c, int d):
alpha(a),
beta(b)
{
m = c; n = d;
cout<<"gamma initialized\n";
}
void show_mn(void)
{
cout<<"m="<<m<<"\n";
cout<<"n="<<n<<"\n";
}
};
void main()
{
gamma g(5, 10.75, 20, 30);
g.show_x();
g.show_y();
g.show_mn();
}

Tuesday 21 April 2020

File Management part-2

HTML tags for Graphics and Tables

Program to shift input data by two bits to the left.

#include<stdio.h>
#include<conio.h>
void main()
{
int x,y;
clrscr();
printf(“Read the integer from keyboard :- ”);
scanf(“%d”,&x);
x<<=3;
y=x;
printf(“\nThe left shifted data is = %d ”,y);
getch();
}

Write a program to input a letter. Find its ASCII code. Reverse the ASCII code and display the equivalent character.

Sample Input: Y
Sample Output: ASCII Code = 89
 Reverse the code = 98
 Equivalent character: b



public class ATS
{
public static void main(String[]args)
{
Scanner in = new Scanner(System.in);
System.out.print("Enter a letter: ");
char l = in.next().charAt(0);
int a = (int)l;
System.out.println("ASCII Code = " + a);
int r = 0;
while (a > 0)
{
int digit = a % 10;           
r = r * 10 + digit;           
a /= 10;       
}
System.out.println("Reversed Code = " + r);
System.out.println("Equivalent character = " + (char)r);
    }
}

Write a program in C++ to highlight the difference between overloaded assignment operator and copy constructor.

#include<iostream.h>
class circle
{
private:   
int   radius;   
float x, y;
public:   
circle( ){     }   
circle( int  rr, float  xx, float  yy )   
{       
radius = rr;       
x = xx;       
y = yy;   
}   
circle  operator =( circle & c )   
{       
cout << endl << "Assignment operator invoked";       
radiius = c.radius;       
x= c.x;       
y= c.y;       
return circle( radius, x, y );   
}   
circle( circle & c )
{       
cout << endl << "copy constructor invoked";       
radius = c.radius;       
x= c.x;       
y= c.y;   
}   
void showdata( )
{       
cout << endl << "Radius = " << radius;       
cout << endl << "X-Coordinate=" << x;       
cout << endl << "Y-Coordinate=" << y;   
}
};
void main( )
{   
circle  c1 ( 10, 2.5, 2.5 );   
circle  c2,c4;   
c4 = c2 = c1;   
circle  c3  = c1;   
c1.showdata( );   
c2.showdata( );   
c3.showdata( );   
c4.showdata( );

Monday 20 April 2020

Program to use switch statement. Display Monday to Sunday.

#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
clrscr();
printf(“enter m for Monday\nt for Tuesday\nw for Wednesday\nh for Thursday\nf for Friday\ns for Saturday\nu for Sunday);
scanf(“%c”,&ch);
switch(ch)
{
case ‘m’:case ‘M’: printf(“monday”);
break;
case ‘t’:case ‘T’: printf(“tuesday”);
break;
case ‘w’:case ‘W’: printf(“wednesday”);
break;
case ‘h’:case ‘H’: printf(“thursday”);
break;
case ‘f ’:case ‘F’: printf(“friday”);
break;
case ‘s’:case ‘S’: printf(“saturday”);
break;
case ‘u’:case ‘U’: printf(“sunday”);
break;
default : printf(“wrong input”);
break;
}
getch();
}

Program print following sequence

ZYXWU
ZYXW
ZYX
ZY
Z


public class ATS
{
public static void main(String[]args)
{
for (int i = 86; i <= 90; i++)
{
for (int j = 90; j >= i; j--)
{
System.out.print((char)j);           
} System.out.println();       
}   
}
}

Write a Program to allocate memory dynamically for an objects of a given class using class’s constructor

#include<iostream.h>
#include<string.h>
#include<conio.h>
class String

char *name; 
int length;
public: 
String() 

length = 0; 
name = new char[length +1]; 

String (char *s) 

length = strlen(s); 
name= new char[length + 1]; 
strcpy(name, s); 

void display(void) 

cout<<name<<"\n"; 

void join(String &a, String &b);
};
void String :: join (String &a, String &b)

length = a.length + b.length;  delete name; 
name = new char [length + 1];
strcpy(name,a.name); 
strcat(name, b.name);
};
int main()
{     
char *first = "Joseph"; 
String name1(first), name2("Louis "), name3("Lagrange"),s1,s2; 
s1.join(name1, name2); 
s2.join(s1, name3); 
name1.display(); 
name2.display(); 
name3.display(); 
s1.display(); 
s2.display();   
return 0;
}

HTML Text Styles and List Tags

Friday 17 April 2020

Program to calculate sum and percentage of 5 subject marks

#include<stdio.h>
#include<conio.h>
void main()
{
int s1,s2,s3,s4,s5,sum,total=500;
float per;
clrscr();
printf(“enter marks of 5 subjects: ”);
scanf(“%d%d%d%d%d”,&s1,&s2,&s3,&s4,&s5);
sum=s1+s2+s3+s4+s5;
printf(“sum=%d”,sum);
per=(sum*100)/total;
printf(“percentage=%f”,per);
getch();
}

Write a program to accept name and total marks of N number of students in two single subscript arrays name[ ] and totalmarks[ ].

Calculate and print: (i) The average of the total marks obtained by N number of students. [average = (sum of total marks of all the students)/N] (ii) Deviation of each student's total marks with the average. [deviation = total marks of a student - average]


import java.util.Scanner;
public class ATS
{
public static void main(String[]args)
{
Scanner in = new Scanner(System.in);
System.out.print("Enter number of students: ");
int n = in.nextInt();
String name[] = new String[n];
int totalmarks[] = new int[n];
int grandTotal = 0;
for (int i = 0; i < n; i++)
{           
in.nextLine();
System.out.print("Enter name of student " + (i+1) + ": ");
        name[i] = in.nextLine();
System.out.print("Enter total marks of student " + (i+1) + ": ");           
totalmarks[i] = in.nextInt();           
grandTotal += totalmarks[i];       
}
double avg = grandTotal / (double)n;
System.out.println("Average = " + avg);
for (int i = 0; i < n; i++)
{
System.out.println("Deviation for " + name[i] + " = " + (totalmarks[i] - avg));       
}   
}
}

Write a Program to overload operators

Write a Program to overload operators like *, <<, >> using friend function. The following overloaded operators should work for a class vector. 

#include<iostream.h>
#include<conio.h>
const size = 3;
class vector
{
int v[size];
public:
vector();
vector(int *x);
friend vector operator *(int a, vector b);
friend vector operator *(vector b, int a);  
friend istream & operator >>(istream &, vector &);
friend ostream & operator <<(ostream &, vector &);
};
vector ::vector()
{
for(int i=0;i<size;i++)
v[i]=0;
}
vector :: vector(int *x)
{
for(int i=0; i<size; i++)
v[i] = x[i];
}
vector operator *(int a, vector b)
{
vector c;
for(int i=0; i<size; i++)
c.v[i] = a * b.v[i];
return c;
}
vector operator *(vector b, int a)
{
vector c;
for(int i=0; i<size; i++)
c.v[i] = b.v[i] * a;  return c;
}
istream & operator >> (istream &din, vector &b)
{
for(int i=0; i<size; i++)
din>>b.v[i];
return(din);
}


ostream & operator << (ostream &dout, vector &b)
{
dout<<"("<<b.v [0];
for(int i=1; i<size; i++)
dout<<","<<b.v[i];
dout<<")";
return(dout);
}
int x[size] = {2,4,6};
int main()
{   
vector m;
vector n = x;
cout<<"Enter Elements of vector m"<<"\n";
cin>>m;
cout<<"\n";
cout<<"m="<<m<<"\n";
vector p,q;
p = 2 * m;
q = n * 2;
cout<<"\n";
cout<<"p="<<p<<"\n";
cout<<"q="<<q<<"\n"; 
return 0;
}

Wednesday 15 April 2020

Simple for loop in C language

Program to print reverse of input number



#include<stdio.h>
#include<conio.h>
void main()
{
int n,a,r=0;
clrscr();
printf(“enter any no to get its reverse: ”);
scanf(“%d”,&n);
while(n>=0)
{
a=n%10;
r=r*10+a;
n=n/10;
}
printf(“reverse=%d”,r);
getch();
}

Program print following sequence

aaaaa
bbbbb
AAAAA
BBBBBB


public class ATS
public static void main(String[]args) 
int a = 97; 
for (int i = 1; i <= 4; i++) 
for (int j = 1; j <= 5; j++) 
System.out.print((char)a + " ");             
}             
a++; 
if (i == 2)                 
a = 65; 
System.out.println();         
}     
}

Write a Program to design a class complex to represent complex numbers. The complex class shuold use an external function



#include<iostream.h>
#include<conio.h>
class complex

float x; 
float y;
public: 
void input(float real, float img) 

x=real; 
y=img; 

friend complex sum(complex, complex); 
void show(complex);
};
complex sum(complex c1, complex c2)

complex c3; 
c3.x = c1.x + c2.x; 
c3.y = c1.y + c2.y; 
return (c3);
}
void complex :: show(complex c)

cout<<c.x<<"+j"<<c.y<<"\n";
}
int main()

complex A,B,C; 
A.input(3.1, 5.65); 
B.input(2.75, 1.2);
C=sum(A,B); 
cout<<"A="; 
A.show(A); 
cout<<"B="; 
B.show(B); 
cout<<"C="; 
C.show(C);   
return 0;
}

Tuesday 14 April 2020

Program:print factorial of an input number

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,fact=1;
clrscr();
printf(“Enter any no: ”);
scanf(“%d”,&n);
for(i=n;i>=1;i--)
{
fact=fact*i;
}
printf(“Factorial=%d”,fact); getch();
}

Program :pattern sequence in java

public class ATS
{
public static void main(String[]args)
{
for (int i = 65; i < 70; i++)
{
for (int j = 65; j <= i; j++)
{
if (i % 2 == 0)
System.out.print((char)(j+32));
else
System.out.print((char)j);           
}
System.out.println();       
}   
}
}

Program:use of virtual function

include<iostream.h>
class Base

public: 
void display() 
{   
cout<<"\n Display Base"; 
}
virtual void show() 
{   
cout<<"\n Show Base:"; 
}
};
class Derived : public Base

public: 
void display() 
{   
cout<<"\n Display Derived"; 
}
void show() 
{   
cout<<"\n Show Derived"; 
}
};
int main()

Base B; 
Derived D; 
Base *bptr;
cout<<"\n bptr points to Base\n"; 
bptr = &B; 
bptr ->display (); 
bptr ->show ();
cout<<"\n\n bptr points to derived\n"; 
bptr = &D; 
bptr ->display (); 
bptr ->show ();
return 0;
}

nested while loop in C Language

while Loop in C Language

Monday 13 April 2020

Program : star sequence program

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
clrscr();
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
printf(“*”);
printf(“\n”);
}
getch();
}

Program: Menu driven program in java

Write a menu driven program to generate the upper case letters from Z to A and lower case letters from 'a' to 'z' as per the user's choice. Enter '1' to display upper case letters from Z to A and Enter '2' to display lower case letters from a to z.


import java.util.Scanner;
public class ATS
{
public static void main(String[]args)
{
Scanner in = new Scanner(System.in);
System.out.println("Enter '1' to display upper case letters from Z to A");
System.out.println("Enter '2' to display lower case letters from a to z");
System.out.print("Enter your choice: ");
int ch = in.nextInt();
int count = 0;
switch (ch)
{
case 1: for (int i = 90; i > 64; i--)
{
char c = (char)i; System.out.print(c);
               
}
break;
case 2: for (int i = 97; i < 123; i++)
{
char c = (char)i; System.out.print(c);           
}
break;
default: System.out.println("Incorrect Choice");
        }   
}
}

Write a program to maintain the records of person with details (Name and Age) and find the eldest among them.

Write a program to maintain the records of person with details (Name and Age) and find the eldest among them. The program must use this pointer to return the result. 



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

char name[20]; 
float age;
public: 
person(char *s, float a) 

strcpy(name, s); 
age = a; 
}
person & person :: greater(person & x) 

if(x.age >= age)   
return x; 
else   
return *this; 
}
void display(void) 

cout<<"Name:"<<name<<"\n"    <<"Age: "<<age<<"\n"; 
}
};
int main()

person p1("John", 37.50),     
p2("Ahmed",29.0),     
p3("Hebber", 40.5);
person p = p1.greater (p3); 
cout<<"Elder Person is:\n"; 
p.display();
p = p1.greater (p2); 
cout<<"Elder Person is:\n"; 
p.display();
return 0;
}

Sunday 12 April 2020

Program: write a program to display input year is leap year or not

#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf(“enter any year: ”);
scanf(“%d”,&n);
if(n%4==0)
printf(“year is a leap year”);
else
printf(“year is not a leap year”);
getch();
}

Program : use of file in C++

Write a program to implement I/O operations on characters. I/O operations includes inputing a string, Calculating length of the string, Storing the String in a file, fetching the stored characters from it, etc.



#include<iostream.h>
#include<fstream.h>
#include<string.h>
int main()

char string[80]; 
cout<<"Enter a String \n"; 
cin>>string; 
int len = strlen(string);
fstream file; 
file.open("TEXT", ios::in | ios::out);
for(int i=0;i<len;i++) 
file.put(string[i]);
file.seekg(0);
char ch; 
while(file) 

file.get(ch); 
cout<<ch; 

return 0;
}

Program : concatenated the product and sum of series

Write a program to input a set of any 10 integer numbers. Find the sum and product of the numbers. Join the sum and product to form a single number. Display the concatenated number. [Hint: let sum=245 and product = 1346 then the number after joining sum and product will be 2451346]


import java.util.Scanner;
public class ATS
{
public static void main(String[]args)
{
Scanner in = new Scanner(System.in);
System.out.println("Enter 10 integers");
long sum = 0, prod = 1;
for (int i = 0; i < 10; i++)
{
int n = in.nextInt();           
sum += n;           
prod *= n;       
}
String s = Long.toString(sum) + Long.toString(prod);
System.out.println("Concatenated Number"+"\t"+s);
    }
}

Saturday 11 April 2020

Program : find greatest among three three numbers

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf(“enter value of a, b & c: ”);
scanf(“%d%d%d”,&a,&b,&c);
if((a>b)&&(a>c))
printf(“a is greatest”);
if((b>c)&&(b>a))
printf(“b is greatest”);
if((c>a)&&(c>b))
printf(“c is greatest”);
getch();
}

Program : Copy all the element of 2 arrays into third array

import java.util.Scanner;
public class ATS
{
public  static void main(String[]args)
{
Scanner in = new Scanner(System.in);
int P[] = new int[6];
int Q[] = new int[4];
int R[] = new int[10];
int i = 0;
System.out.println("Enter 6 elements of array P:");
for (i = 0; i < P.length; i++)
{
P[i] = in.nextInt();
        }
System.out.println("Enter 4 elements of array Q:");
for (i = 0; i < Q.length; i++)
{
Q[i] = in.nextInt();       
}
        i = 0;
while(i < P.length)
{
R[i] = P[i];           
i++;       
}
int j = 0;
while(j < Q.length)
{
R[i++] = Q[j++];       
}
System.out.println("Elements of Array R:");
for (i = 0; i < R.length; i++)
{
System.out.print(R[i] + " ");       
}   
}
}

Program : display matrix using class in c++

Write a Program to design a class to represent a matrix. The class should have the functionality to insert and retrieve the elements of the matrix.



#include<iostream.h>
class matrix

int **p; 
int d1,d2;
public: 
matrix(int x, int y); 
void get_element(int i, int j, int value) 

p[i][j]=value; 

int & put_element(int i, int j) 

return p[i][j]; 
}
};
matrix ::matrix(int x, int y)

d1 = x;  d2 = y; 
p = new int *[d1]; 
for(int i = 0; i < d1; i++) 
p[i] = new int[d2];
}
int main()

int m, n;
cout<<"Enter size of matrix"; 
cin>>m>>n; 
matrix A(m,n); 
cout<<"Enter Matrix Element row by row:"; 
int i,j,value;
for(i=0;i<m;i++) 
for(j=0;j<n;j++) 
{   
cin>>value;   
A.get_element(i,j,value); 

cout<<"\n";
for(i=0;i<m;i++)

for(j=0;j<n;j++) 
cout<<A.put_element(i,j);
cout<<"\n";

return 0;
}

Friday 10 April 2020

WAP in Java to accept an integer number & display its corresponding letter

WAP in Java to accept an integer number N such that 0<N<27 Display the corresponding letter of the alphabet 


import java.util.Scanner;
public class ATS{
public static void main(String[]args)
{
    Scanner in = new Scanner(System.in);
    System.out.print("Enter integer: ");
    int n = in.nextInt();
    if (n > 0 && n < 27)
    {
        char ch =(char)(n + 64);
        System.out.println("Corresponding letter = " + ch);       
    }
    else
    {
        System.out.println("Please enter a number in 1 to 26 range");       
    }

}
}

Program: Write a Program using copy constructor to copy data of an object to another object.

#include<iostream.h>
#include<conio.h>
class code

int id;
public: 
code(){} 
code(int a) 

id = a; 

code(code & x) 

id = x.id; 

void display(void) 

cout<<id; 
}
};
int main()
{     
code A(100); 
code B(A); 
code C = A; 
code D; 
D = A; 
cout<<"\n id of A:"; 
A.display(); 
cout<<"\n id of B:"; 
B.display(); 
cout<<"\n id of C:"; 
C.display(); 
cout<<"\n id of D:";
D.display(); 
return 0;