# Question 2

(a) (ii) Explain the concept of Class and Object used in C++ giving suitable example.

```#include<iostream.h>class students{	public:		char *name;		int rollNo;		float cpi;		int sem;}main(){	students s;	s.name = "Jaydip";	s.rollNo = 1;	s.cpi = 7.5;	s.sem = 7;	cout << "\nStudent Name : " << s.name;	cout << "\nStudent Roll No : " << s.rollNo;	cout << "\nStudent CPI : " << s.cpi;	cout << "\nStudent Semester : " << s.sem;}
```

# Question 3

(a) Write a program to generate fibbonacci series of numbers (total 20 numbers)
i.e. 1, 1, 2, 3, 5, 8….etc

```#include<stdio.h>#include<conio.h>void main(){	int i,a=1,b=0,sum;	clrscr();	for(i=0;i<20;i++)	{		sum = a + b;		a = b;		b = sum;		printf("%d ",sum); 			}		getch();}
```

(c) Write a program to store 10 numbers in an array. Then find out Sum, Maximum and Average of these 10 numbers.

```#include<stdio.h>#include<conio.h>main(){	int number[10],sum=0,i,maximum = 0;	float average;	clrscr();	for(i=0;i<10;i++)	{		printf("Enter Number %d : ",i+1);		scanf("%d",&number[i]);	}	printf("\nSum of all Numbers : ");	for(i=0;i<10;i++)	{		sum += number[i];	}	printf("%d",sum);	printf("\nAverage of all Numbers : ");	average = sum/10;	printf("%f",average);	printf("\nMaximum Number is : ");	for(i=0;i<10;i++)	{		if(maximum < number[i])			maximum = number[i];	}	printf("%d",maximum);	getch();}
```

(b) Write a program to convert temperature entered by user from Fahrenhit into Celcius.

```#include<stdio.h>#include<conio.h>#include<math.h>void main(){	float t=0,z=0;	clrscr();	printf("\nEnter the tempreature = ");	scanf("%f",&t);	z=((t-32)*5)/9;	printf("\n Tempreature in calcius = %f",z);	getch();}
```

(c) Write a C++ program which is having class named student .It has two member functions named “read_data()” and “print_data()”. It has member elements called Rollno,Name and Percentage. Assume suitable data type for variable. And read the data from the user and print the same on the screen using above functions.

`#include<iostream.h>class students{	char *Name;	int RollNo;	float Percentage;	public :	void read_data(void)	{		cout << "\nEnter Name : ";		cin >> Name;		cout << "\nEnter Roll No : ";		cin >> RollNo;		cout << "\nEnter Percentage : ";		cin >> Percentage;	}	void print_data(void)	{		cout << "\n\n\nStudent Name : " << Name;		cout << "\nStudent Roll No : " << RollNo;		cout << "\nStudent Percentage : " << Percentage;	}}  main(){	students s;	s.read_data();	s.print_data();}`

# Question 4

(a) Write a program to read two 5 X 5 matrices from the user and store the Addition of two matrices in the resultant matrix.
i.e. C=A + B , where A,B,C each one is 5 X 5 Matrix.

```#include<stdio.h>#include<conio.h>main(){	int A[5][5],B[5][5],C[5][5],i,j;	clrscr();	printf("\n\n Enter First Matrix's Element : \n");	for(i=0;i<3;i++)	{		for(j=0;j<3;j++)		{			printf("\nA[%d][%d] = ",i,j);			scanf("%d",&A[i][j]);		}	}	printf("\n\n Enter Second Matrix's Element : \n");	for(i=0;i<3;i++)	{		for(j=0;j<3;j++)		{			printf("\nB[%d][%d] = ",i,j);			scanf("%d",&B[i][j]);		}	}	for(i=0;i<3;i++)	{		for(j=0;j<3;j++)		{			C[i][j] = A[i][j] + B[i][j];		}	}	printf("\n\n Sum of Two Matrix : \n");	for(i=0;i<3;i++)	{		for(j=0;j<3;j++)		{			printf("%d ",C[i][j]);		}		printf("\n");	}	getch();}
```

(a) What is pointer? Give its benefits. Write a program to do swapping of two elements using function with two pointers as arguments.

```#include<stdio.h>#include<conio.h>void swapNumbers(int *,int *);main(){	int x,y;	clrscr();	x = 10;	y = 20;	printf("Current value of X and Y is : %d and %d ",x,y);	swapNumbers(&x,&y);	printf("\n\nAfter swapping value of X and Y is : %d and %d ",x,y);	getch();}void swapNumbers(int *a,int *b){	int temp;	temp = *a;	*a = *b;	*b = temp;}
```

# Question 5

(a) Explain the syntax of switch…case statement. Write a program using switch…case statement.

```#include<stdio.h>#include<conio.h>void main(){	int a,b,choice;	clrscr();	printf("\nEnter Number 1 : ");	scanf("%d",&a);	printf("\nEnter Number 2 : ");	scanf("%d",&b);	printf("Enter Choice : ");	printf("\n1. Add");	printf("\n2. Subtract");	printf("\n3. Multiply");	printf("\n4. Divide\n\n\t : ");	scanf("%d",&choice);	switch(choice)	{		case 1 :			printf("Addition : %d",a+b);			break;		case 2 :			printf("Subtraction : %d",a-b);			break;		case 3 :			printf("Multiplication : %d",a*b);			break;		case 4 :			printf("Divided : %d",a/b);			break;		default :			printf("Your Choice is Wrong");			break;	}	getch();}
```

(b) Write a program to print the following triangle for n lines
*
* *
* * *
* * * *
…upto n such Lines

```#include<stdio.h>#include<conio.h>main(){	int number,i,j;	clrscr();	printf("\nEnter Number : ");	scanf("%d",&number);	printf("\n\n");	for(i=1;i<=number;i++)	{		for(j = (number-1);j>=i;j--)			printf(" ");		for(j=1;j<=i;j++)			printf("* ");		for(j = (number-1);j>=i;j--)			printf(" ");			printf("\n");	}	getch();}
```

(b) Write a C Program to check whether the given number is prime or not.

```#include<stdio.h>#include<conio.h>void main(){	int number,stop=0,i;	clrscr();	printf("\nEnter Number : ");	scanf("%d",&number);	for(i=2;i<number;i++)	{		if( (number%i) == 0)		{			stop = 1;			break;		}	}	if(stop == 1 || number == 0 || number == 1)		printf("\nNumber is not prime.");	else		printf("\nNumber is prime.");	getch();}
```