You are on page 1of 13

Q1)

Code:
#include<iostream>

using namespace std;

int main(){

int N, i, j, isPrime, n;

cout << "Enter the value of N\n";


cin >> N;

for(i = 2; i <= N; i++){


isPrime = 0;

for(j = 2; j <= i/2; j++){

if(i % j == 0){
isPrime = 1;
break;
}
}

if(isPrime==0 && N!= 1)


cout << i << " ";
}

return 0;
}
Q2)
Code
#include<iostream>
using namespace std;
int main ()
{
int arr[10], n, i, max, min;
cout << "Enter the size of the array : ";
cin >> n;
cout << "Enter the elements of the array : ";
for (i = 0; i < n; i++)
cin >> arr[i];
max = arr[0];
for (i = 0; i < n; i++)
{
if (max < arr[i])
max = arr[i];
}
min = arr[0];
for (i = 0; i < n; i++)
{
if (min > arr[i])
min = arr[i];
}
cout << "Largest element : " << max;
cout <<endl<< "Smallest element : " << min;
return 0;
}
Output:

Q3)
Code:
#include <bits/stdc++.h>
using namespace std;
class name
{
// Access specifier
public:

// Data Members
string sirname;

// Member Functions()
void printname()
{
cout << "Sirname is: " << sirname;
}
};

int main() {

// Declare an object of class geeks


name obj1;

// accessing data member


obj1.sirname = "Dixit";

// accessing member function


obj1.printname();
return 0;
}
Output:

Q4)
Code:
#include <iostream>
using namespace std;

class construct
{
public:
int a, b;
// Default Constructor
construct()
{
a = 10;
b = 20;
}
};
class copy_const
{
private:
double x, y;

public:
//copy constructor
copy_const(double px, double py)
{
x = px, y = py;
}
};
class Point
{
private:
int x, y;

public:
// Parameterized Constructor
Point(int x1, int y1)
{
x = x1;
y = y1;
}

int getX()
{
return x;
}
int getY()
{
return y;
}
};
int main()
{
// Default constructor called automatically
// when the object is created
construct c;
cout << "a: " << c.a << endl
<< "b: " << c.b;

//calling Paramatrized Constructor


Point p1(10, 15);

// Access values assigned by constructor


cout << "p1.x = " << p1.getX() << ", p1.y = " <<
p1.getY();

//****Copy Constructor*****
copy_const a[10];
copy_const b = copy_const(5, 6);
return 1;
}
Q5)
Code
#include <iostream>
#include<bits/stdc++.h>
using namespace std;

#define max 100

class Student
{
string s_name;
int marks[5];
int Total;
int Tmax;
public:
void assign()
{
cout<< endl << "Enter the student details" <<
endl;
cout<< "Name of the Student: ";
cin>> s_name;
cout<< "Marks secured: "<<endl;
for(int i=0;i<3;i++)
{
if(i==0){
cout<<"1)Maths ";
cin>> marks[i];
}
else if(i==1){
cout<<"2) Hindi ";
cin>>marks[i];
}
else
{
cout<<"3) English ";
cin>>marks[i];
}
}
}
void compute()
{
Total=0;
for(int i=0;i<3;i++)
{
Total=Total+marks[i];
}
Tmax=Total;
}

void display()
{
cout << "Name of the Student : " << s_name <<
endl;
cout<< "Marks secured: "<<endl;

for(int i=0;i<3;i++)
{
if(i==0){
cout<<"1)Maths ";
cout<< marks[i]<<endl;
}
else if(i==1){
cout<<"2) Hindi ";
cout<<marks[i]<<endl;
}
else
{
cout<<"3) English ";
cout<<marks[i]<<endl;
}
}
cout<<endl<<"Total Marks Obtained :"<<Total;
cout<<endl<<"Total Max Number
secured :"<<Tmax;

}
};
int main()
{
Student stud;
stud.assign();
stud.compute();
stud.display();

return 0;
}
Output:

You might also like