Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

Programming for Problem Solving (9)

This document is a practical file for the Object Oriented Programming with Java Lab course at IMS Engineering College, detailing various programming assignments completed by a student named Arpita Srivastava. It includes a comprehensive index of experiments, each with a brief description and source code for Java programs that cover fundamental programming concepts such as calculations, data structures, and control statements. The file serves as a record of the student's practical work in the course for the academic session 2023-24.

Uploaded by

arpitasri1305
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Programming for Problem Solving (9)

This document is a practical file for the Object Oriented Programming with Java Lab course at IMS Engineering College, detailing various programming assignments completed by a student named Arpita Srivastava. It includes a comprehensive index of experiments, each with a brief description and source code for Java programs that cover fundamental programming concepts such as calculations, data structures, and control statements. The file serves as a record of the student's practical work in the course for the academic session 2023-24.

Uploaded by

arpitasri1305
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 38

IMS Engineering College

NH-09, Adhyatmik Nagar, Near Dasna, Distt. Ghaziabad, U.P.

Practical File
of
“OBJECT ORIENTED PROGRAMMING
WITH JAVA LAB (BCS-452)”
B.Tech IInd Year

Semester :IVth

Branch: Computer Science

Session : 2023-24(Even)

Submitted By : ARPITA SRIVASTAVA

Roll No. : 2201430120031

Name of Faculty: Ms. SONIA SHARMA


INDEX
S.NO NAME OF EXPERIMENT DATE SIGN.
1. WAP that accepts the marks of 5 subjects and finds the
sum and percentage marks obtained by the student.
WAP that calculates the Simple Interest and Compound
2. Interest. The Principal , Amount , Rate of Interest and
Time are entered through the keyboard.
WAP to calculate the area and circumference of a
3. circle.
WAP that accepts the temperature in Centigrade and
4. converts into Fahrenheit using the formula C/5=(F-
32)/9.
WAP that swaps values of two variables using a third
5. variable.
WAP that checks whether the two numbers entered by
6. the user are equal or not.
WAP to find the greatest of three numbers.
7.
WAP that finds whether a given number is even or odd.
8.
WAP that tells whether a given year is a leap year or
9. not.
WAP that accepts marks of five subjects and finds
10. percentage and prints grades according to the
following criteria:
Between 90-100%-----Print ‘A’
80-90%-----------------Print ‘B’
60-80%-----------------Print ‘C’
Below 60%-------------Print ‘D’
WAP that takes two operands and one operator from
11. the user, perform the operation, and prints the result
by using Switch statement.
WAP to print the sum of all numbers up to a given
12. number.
WAP to find the factorial of a given number.
13.
WAP to print sum of even and odd numbers from 1 to N
14. numbers.
WAP to print the Fibonacci series.
15.
WAP to check whether the entered number is prime or
16. not.
WAP to find the sum of digits of the entered number.
17.
WAP to find the reverse of a number.
18.
WAP to print Armstrong numbers from 1 to 100.
19.
WAP to convert binary number into decimal number
20. and vice versa.
WAP that simply takes elements of the array from the
21. user and finds the sum of these elements.
WAP that inputs two arrays and saves sum of
22. corresponding elements of these arrays in a third array
and prints them.
WAP to find the minimum and maximum element of the
23. array.
WAP to search an element in a array using Linear
24. Search.
WAP to sort the elements of the array in ascending
25. order using Bubble Sort technique.
WAP to add and multiply two matrices of order nxn.
26.
WAP that finds the sum of diagonal elements of amxn
27. matrix.
WAP to implement strlen (), strcat (),strcpy () using the
28. concept of Functions.
Define a structure data type TRAIN_INFO. The type
29. contain Train No.: integer type Train name: string
Departure Time: aggregate type TIME Arrival Time:
aggregate type TIME Start station: string End station:
string The structure type Time contains two integer
members: hour and minute. Maintain a train timetable
and implement the following operations:
a. List all the trains (sorted according to train number)
that depart from a particular section.
b. List all the trains that depart from a particular
station at a particular time.
c. List all he trains that depart from a particular station
within the next one hour of a given time.
d. List all the trains between a pair of start station and
end station.
WAP to swap two elements using the concept of
30. pointers.
WAP to compare the contents of two files and
31. determine whether they are same or not.
WAP to check whether a given word exists in a file or
32. not. If yes then find the number of times it occurs.
PROGRAM-1:WAP that accepts the marks of 5 subjects and finds the sum and percentage
marks obtained by the student.

SOURCE CODE:

#include<stdio.h>

#include<conio.h>

void main()

inta,b,c,d,e,sum,perc;

intclrscr();

printf("\tSUM AND PERCENTAGE OF MARKS!!!\n");

printf("ENTER THE MARKS OF FIRST SUBJECT:");

scanf("%d",&a);

printf("ENTER THE MARKS OF SECOND SUBJECT:");

scanf("%d",&b);

printf("ENTER THE MARKS OF THIRD SUBJECT:");

scanf("%d",&c);

printf("ENTER THE MARKS OF FOURTH SUBJECT:");

scanf("%d",&d);

printf("ENTER THE MARKS OF FIFTH SUBJECT:");

scanf("%d",&e);

sum=(a+b+c+d+e);

perc=(sum*100/500);

printf("THE SUM OF MARKS OBTAINED:%d\n",sum);

printf("THE PERCENTAGE OF MARKS OBTAINED:%d\n",perc);

intgetch();

OUTPUT:
PROGRAM-2: WAP that calculates the Simple Interest and Compound Interest. The Principal
, Amount , Rate of Interest and Time are entered through the keyboard.

SOURCE CODE:

#include <stdio.h>

#include <conio.h>

#include <math.h>

int main()

floatp,r,t,amount,si,ci;

intclrscr();

printf("\tSIMPLE AND COMPOUND INTEREST!\n");

printf("Enter the value of Principle :");

scanf("%f",&p);

printf("Enter the value of Rate :");

scanf("%f",&r);

printf("Enter the period of Time :");

scanf("%f",&t);

si=(p*r*t)/100;

amount=p*((pow((1+r/100),t)));

ci=amount-p;

printf("The value of Simple interest is :%f\n",si);

printf("The value of Compound interest is :%f\n",ci);

printf("The Amount is :%f\n",amount);

int getch();

OUTPUT:
PROGRAM-3: WAP to calculate the area and circumference of a circle
SOURCE CODE:

#include <stdio.h>

#include <conio.h>

int main()

floatr,pi=3.14,a,c;

intclrscr();

printf("\tAREA OF CIRCLE!\n");

printf("Enter the value of radius:");

scanf("%f",&r);

a=pi*r*r;

c=2*pi*r;

printf("Area of circle is : %f\n",a);

printf("Circumference of circle is :%f\n",c);

intgetch();

OUTPUT:
PROGRAM-4: WAP that accepts the temperature in Centigrade and converts into Fahrenheit
using the formula C/5=(F-32)/9.
SOURCE CODE:

#include <stdio.h>

#include <conio.h>

void main()

floatc,f;

intclrscr();

printf("\tTEMPRATURE CONVERSION!\n");

printf("Enter temprature in Degree Celsius :");

scanf("%f",&c);

f=((9*c)/5)+32;

printf("Temprature in Farenheit is :%f",f);

intgetch();

OUTPUT:
PROGRAM-5: WAP that swaps values of two variables using a third variable.
SOURCE CODE:

#include <stdio.h>

#include <conio.h>

int main()

doublea,b,c;

intclrscr();

printf("\t SWAPPING NUMBERS \n");

printf("Enter the value of a:");

scanf("%lf",&a);

printf("Enter the value of b:");

scanf("%lf",&b);

c=a;

a=b;

b=c;

printf("After swaping\n");

printf("First number is :%2lf\n",a);

printf("Second number is :%2lf\n",b);

return 0;

OUTPUT:
PROGRAM-6: WAP that checks whether the two numbers entered by the user are equal or
not.
SOURCE CODE:

#include<stdio.h>

#include<conio.h>

int main()

inta,b;

intclrscr();

printf("\tEQUAL NUMBERS\n");

printf("ENTER THE FIRST NUMBER(A):");

scanf("%d",&a);

printf("ENTER THE SECOND NUMBER(B):");

scanf("%d",&b);

if (a == b)

printf("A and B are equal\n",a,b);

else

printf("A and B are not equal\n");

intgetch();

OUTPUT:
PROGRAM-7: WAP to find the greatest of three numbers.
SOURCE CODE:

#include <stdio.h>

int main()

int A, B, C;

printf("\tLARGEST OF THREE NUMBERS\n");

printf("Enter the numbers A, B and C: ");

scanf("%d %d %d", &A, &B, &C);

if (A >= B && A >= C)

printf("%d is the largest number.", A);

if (B >= A && B >= C)

printf("%d is the largest number.", B);

if (C >= A && C >= B)

printf("%d is the largest number.", C);

return 0;

OUTPUT:
PROGRAM-8: WAP that finds whether a given number is even or odd.
SOURCE CODE:

#include<stdio.h>

#include<conio.h>

int main()

intnum;

printf("\tEVEN OR ODD\n");

printf("Enter the number:");

scanf("%d",&num);

if (num%2==0)

printf("NUMBER %d IS EVEN",num);

else

printf("NUMBER %d IS ODD",num);

return 0;

OUTPUT:
PROGRAM-9:WAP that tells whether a given year is a leap year or not.
SOURCE CODE:

#include <stdio.h>

int main()

int year;

printf("\tLEAP YEAR\n");

printf("Enter a year: ");

scanf("%d", &year);

if (year % 400 == 0)

printf("%d is a leap year.", year);

else if (year % 100 == 0)

printf("%d is not a leap year.", year);

else if (year % 4 == 0)

printf("%d is a leap year.", year);

else

printf("%d is not a year.", year);

return 0;

OUTPUT:
PROGRAM-10:WAP that accepts marks of five subjects and finds percentage and prints grades
according to the following criteria:
Between 90-100%-----Print ‘A’
80-90%-----------------Print ‘B’
60-80%-----------------Print ‘C’
Below 60%-------------Print ‘D’
SOURCE CODE:

#include<stdio.h>

#include<conio.h>

int main()

inta,b,c,d,e,sum,perc;

printf("\tPERCENTAGE AND GRADE!!!\n");

printf("ENTER THE MARKS OF FIRST SUBJECT:");

scanf("%d",&a);

printf("ENTER THE MARKS OF SECOND SUBJECT:");

scanf("%d",&b);

printf("ENTER THE MARKS OF THIRD SUBJECT:");

scanf("%d",&c);

printf("ENTER THE MARKS OF FOURTH SUBJECT:");

scanf("%d",&d);

printf("ENTER THE MARKS OF FIFTH SUBJECT:");

scanf("%d",&e);

sum=(a+b+c+d+e);

perc=(sum*100/500);

printf("THE PERCENTAGE OF MARKS OBTAINED:%d\n",perc);

if(perc>=90&&perc<=100)

printf("Grade A");

else if(perc>=80&&perc<90)

printf("Grade B");

else if(perc>=60&&perc<80)

printf("Grade C");
}

else if(perc<60)

printf("Grade D");

return 0;

OUTPUT:
PROGRAM-11:WAP that takes two operands and one operator from the user, perform the operation,
and prints the result by using Switch statement.
SOURCE CODE:

#include<stdio.h>

#include<conio.h>

int main()

int num1,num2,c,choice;

printf("\tOPERATORS\n");

printf("ENTER THE FIRST OPERAND:");

scanf("%d",&num1);

printf("ENTER THE SECOND OPERAND:");

scanf("%d",&num2);

printf("SELECT OPERATOR:\n");

printf("ADDITION =1\n");

printf("SUBSTRACT=2\n");

printf("MULTIPLY =3\n");

printf("DIVISION =4\n");

printf("Enter your choice=");

scanf("%d",&choice);

switch(choice)

case 1:

c=num1+num2;

printf("SUM=%d\n",c);

break;

case 2:

c=num1-num2;

printf("SUBSTRACTION=%d\n",c);

break;

case 3:

c=num1*num2;

printf("MULTIPLY=%d\n",c);

break;

case 4:
c=num1/num2;

printf("DIVISION=%d\n",c);

break;

default:

printf("OPERATOR NOT VALID");

return 0;

OUTPUT:
PROGRAM-12:WAP to print the sum of all numbers up to a given number.
SOURCE CODE:

#include <stdio.h>

#include <conio.h>

void main()

intnum, i, sum = 0;

printf("\tSUM TO A GIVEN NUMBER\n");

printf(" Enter a number: ");

scanf("%d", &num);

for (i = 0; i<= num; i++)

sum = sum + i;

printf("Sum of numbers upto %d is: %d", num, sum);

intgetch();

OUTPUT:
PROGRAM-13:WAP to find the factorial of a given number.
SOURCE CODE:

#include<stdio.h>

#include<conio.h>

int main()

inti=1,fact=1,n;

printf("\tFACTORIAL OF A NUMBER\n");

printf("ENTTER A NUMBER:");

scanf("%d",&n);

while (i<=n)

fact=fact*i;

i++;

printf("FACTORIAL OF %d IS %d\n",n,fact);

return 0;

OUTPUT:
PROGRAM-14:WAP to print sum of even and odd numbers from 1 to N
numbers.
SOURCE CODE:

#include <stdio.h>

void main()

inti, num, sumE= 0, sumO= 0;

printf("\tSUM OF ODD EVEN UPTO N\n");

printf("Enter the value of num:");

scanf("%d", &num);

for (i = 1; i<= num; i++)

if (i % 2 == 0)

sumE = sumE + i;

else

sumO = sumO + i;

printf("Sum of all odd numbers = %d\n", sumO);

printf("Sum of all even numbers = %d\n", sumE);

OUTPUT:
PROGRAM-15:WAP to print the Fibonacci series.
SOURCE CODE:

#include <stdio.h>

int main()

inti, n,t1 = 0, t2 = 1,nextTerm = t1 + t2;

printf("\tFIBONACCI SERIES\n");

printf("Enter the number of terms: ");

scanf("%d", &n);

printf("Fibonacci Series: %d, %d, ", t1, t2);

for (i = 3; i<= n; ++i)

printf("%d, ", nextTerm);

t1 = t2;

t2 = nextTerm;

nextTerm = t1 + t2;

return 0;

OUTPUT:
PROGRAM-16:WAP to check whether the entered number is prime or not.
SOURCE CODE:

#include <stdio.h>

int main()

int n, i, c = 0;

printf("\t PRIME NUMBERS\n");

printf("Enter any number n:");

scanf("%d", &n);

for (i = 1; i<= n; i++)

if (n % i == 0)

c++;

if (c == 2)

printf("%d is a Prime number",n);

else

printf("%d is not a Prime number",n);

return 0;

OUTPUT:
PROGRAM-17:WAP to find the sum of digits of the entered number.
SOURCE CODE:

#include<stdio.h>

int main()

intn,sum=0,m;

printf("\tSUM OF DIGITS\n");

printf("Enter a number:");

scanf("%d",&n);

while(n>0)

m=n%10;

sum=sum+m;

n=n/10;

printf("Sum is=%d",sum);

return 0;

OUTPUT:
PROGRAM-18: WAP to find the reverse of a number.
SOURCE CODE:

#include <stdio.h>

int main()

int number, reversed = 0;

printf("\tREVERSE OF A NUMBER\n");

printf("Enter any number = ");

scanf("%d", &number);

while(number !=0)

reversed = (reversed * 10) + (number % 10);

number /= 10;

printf("Reverse = %d", reversed);

return 0;

OUTPUT:
PROGRAM-19:WAP to print Armstrong numbers from 1 to 100.
SOURCE CODE:

#include <stdio.h>

int main()

inti,n,r,sum=0;

printf("\tARMSTRONG NUMBERS BETWEEN 1 TO 100\n");

printf("ARMSTRONG NUMBERS ARE:\n");

for (i=1;i<=100;i++)

sum=0;

n=i;

while(n!=0)

r=n%10;

sum=sum+(r*r*r);

n=n/10;

if(i==sum)

printf("%d",i);

return 0;

OUTPUT:
PROGRAM-20:WAP to convert binary number into decimal number and vice
versa.
SOURCE CODE:

~BINARY TO DECIMAL:

#include <stdio.h>

#include <conio.h>

void main()

intnum, binary_num, decimal_num = 0, base = 1, rem;

printf("\tBINARY TO DECIMAL CONVERSION\n");

printf (" Enter a binary number with the combination of 0s and 1s: ");

scanf (" %d", &num);

binary_num = num;

while ( num> 0)

rem = num % 10;

decimal_num = decimal_num + rem * base;

num = num / 10;

base = base * 2;

printf ( " The binary number is %d \t", binary_num);

printf (" \n The decimal number is %d \t", decimal_num);

intgetch();

OUTPUT:
~DECIMAL TO BINARY :

#include <stdio.h>

int main()

int a[10], number, i, j;

printf("\tDECIMAL TO BINARY\n");

printf("ENTER A NUMBER : ");

scanf("%d", &number);

for(i = 0; number > 0; i++)

a[i] = number % 2;

number = number / 2;

printf("Binary Number of a Given Number = ");

for(j = i - 1; j >= 0; j--)

printf(" %d ", a[j]);

printf("\n");

return 0;

OUTPUT:
PROGRAM-21:WAP that simply takes elements of the array from the user and finds the sum of these
elements.
SOURCE CODE:

#include<stdio.h>

int main()

intarr[100], size, i, sum = 0;

printf("\tSUM OF ELEMENTS OF ARRAY\n");

printf("Enter array size:");

scanf("%d",&size);

printf("Enter array elements:");

for(i = 0; i< size; i++)

scanf("%d",&arr[i]);

for(i = 0; i< size; i++)

sum = sum + arr[i];

printf("Sum of the array = %d\n",sum);

return 0;

OUTPUT:
PROGRAM-22:WAP that inputs two arrays and saves sum of corresponding elements of these arrays in
a third array and prints them.
SOURCE CODE:

#include<stdio.h>

void main()

int i,ar1[5],ar2[5],sum[5];

printf("\tSUM OF ARRAYS\n");

printf("Enter first array:-\n");

for(i=0;i<=4;i++)

printf("ar1[%d]=",i);

scanf("%d",&ar1[i]);

printf("Enter second array:-\n");

for(i=0;i<=4;i++)

printf("ar2[%d]=",i);

scanf("%d",&ar2[i]);

for(i=0;i<=4;i++)

sum[i]=ar1[i]+ar2[i];

printf("Sum of arrays:-");

for(i=0;i<=4;i++)

printf("\nsum[%d]=%d",i,sum[i]);

OUTPUT:
PROGRAM-23:WAP to find the minimum and maximum element of the array.
SOURCE CODE:

#include <stdio.h>

#include <conio.h>

int main()

int a[1000],i,n,min,max;

printf("\tMIN AND MAX ELEMENT OF ARRAY\n");

printf("Enter size of the array : ");

scanf("%d",&n);

printf("Enter elements in array : ");

for(i=0; i<n; i++)

scanf("%d",&a[i]);

min=max=a[0];

for(i=1; i<n; i++)

if(min>a[i])

min=a[i];

if(max<a[i])

max=a[i];

printf("minimum of array is : %d",min);

printf("\nmaximum of array is : %d",max);

return 0;

OUTPUT:
PROGRAM-24:WAP to search an element in a array using Linear Search.
SOURCE CODE:

#include <stdio.h>

int main()

int array[100], search, c, number;

printf("\tLINEAR SEARCH\n");

printf("Enter the number of elements in array:");

scanf("%d",&number);

printf("Enter %d numbers:", number);

for ( c = 0 ; c < number ; c++ )

scanf("%d",&array[c]);

printf("Enter the number to search:");

scanf("%d",&search);

for ( c = 0 ; c < number ; c++ )

if ( array[c] == search )

printf("%d is present at location %d.\n", search, c+1);

break;

if ( c == number )

printf("%d is not present in array.\n", search);

return 0;

OUTPUT:
PROGRAM-25:WAP to sort the elements of the array in ascending order using Bubble Sort
technique.
SOURCE CODE:

#include <stdio.h>

int main()

int array[100], n, c, d, swap;

printf("\tBUBBLE SORT\n");

printf("Enter number of elements:");

scanf("%d", &n);

printf("Enter %d integers\n", n);

for (c = 0; c < n; c++)

scanf("%d", &array[c]);

for (c = 0 ; c < n - 1; c++)

for (d = 0 ; d < n - c - 1; d++)

if (array[d] > array[d+1])

swap = array[d];

array[d] = array[d+1];

array[d+1] = swap;

printf("Sorted list in ascending order:\n");

for (c = 0; c < n; c++)

printf("%d\t", array[c]);

return 0;

OUTPUT:
PROGRAM-26:WAP to add and multiply two matrices of order nxn.
SOURCE CODE:

MULTIPLY OF MATRICES:

#include<stdio.h>

int main()

int a[10][10],b[10][10],mul[10][10],r,c,i,j,k;

printf("\tMULTIPLYING OF MATRICES\n");

printf("enter the number of row=");

scanf("%d",&r);

printf("enter the number of column=");

scanf("%d",&c);

printf("enter the first matrix element=\n");

for(i=0;i<r;i++)

for(j=0;j<c;j++)

scanf("%d",&a[i][j]);

printf("enter the second matrix element=\n");

for(i=0;i<r;i++)

for(j=0;j<c;j++)

scanf("%d",&b[i][j]);

printf("multiply of the matrix=\n");

for(i=0;i<r;i++)
{

for(j=0;j<c;j++)

mul[i][j]=0;

for(k=0;k<c;k++)

mul[i][j]+=a[i][k]*b[k][j];

for(i=0;i<r;i++)

for(j=0;j<c;j++)

printf("%d\t",mul[i][j]);

printf("\n");

return 0;

OUTPUT:
ADDITION OF MATRICES:

#include<stdio.h>

int main()

int m, n, c, d, first[10][10], second[10][10], sum[10][10];

printf("\tADDITION OF MATRICES\n");

printf("Enter the number of rows and columns of matrix:");

scanf("%d%d", & m, & n);

printf("Enter the elements of first matrix:");

for (c = 0; c < m; c++)

for (d = 0; d < n; d++) scanf("%d", & first[c][d]);

printf("Enter the elements of second matrix:");

for (c = 0; c < m; c++)

for (d = 0; d < n; d++) scanf("%d", & second[c][d]);

printf("Sum of entered matrices:-\n");

for (c = 0; c < m; c++)

for (d = 0; d < n; d++)

sum[c][d] = first[c][d] + second[c][d];

printf("%d\t", sum[c][d]);

printf("\n");

return 0;

OUTPUT:
PROGRAM-27:WAP that finds the sum of diagonal elements of amxn matrix.
SOURCE CODE:

#include<stdio.h>

void main()

int mat[12][12];

inti,j,row,col,sum=0;

printf("\tSUM OF DIAGONAL ELEMENTS OF MATRIX\n");

printf("Enter the number of rows and columns for matrix:");

scanf("%d%d",&row,&col);

printf("Enter the elements of the matrix:\n");

for(i=0;i<row;i++)

for(j=0;j<col;j++)

scanf("%d",&mat[i][j]);

printf("The matrix:\n");

for(i=0;i<row;i++)

for(j=0;j<col;j++)

printf("%d\t",mat[i][j]);

printf("\n");

for(i=0;i<row;i++)

for(j=0;j<col;j++)

if(i==j)

sum=sum+mat[i][j];
}

printf("The sum of diagonal elements of a square matrix = %d\n",sum);

OUTPUT:

You might also like