0% found this document useful (0 votes)
48 views9 pages

Rajshahi University of Engineering & Technology

The document describes 4 assignments for an Object Oriented Programming course. [1] The first assignment involves creating a class to determine if a given number is prime or not. [2] The second assignment uses a class to find all prime numbers between 1 and 1000. [3] The third assignment modifies the class to find prime numbers within a user-input range. [4] The fourth assignment sums all the prime numbers found in the third assignment.

Uploaded by

Adittya Podder
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views9 pages

Rajshahi University of Engineering & Technology

The document describes 4 assignments for an Object Oriented Programming course. [1] The first assignment involves creating a class to determine if a given number is prime or not. [2] The second assignment uses a class to find all prime numbers between 1 and 1000. [3] The third assignment modifies the class to find prime numbers within a user-input range. [4] The fourth assignment sums all the prime numbers found in the third assignment.

Uploaded by

Adittya Podder
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Heaven’s light is our guide

RAJSHAHI UNIVERSITY OF ENGINEERING & TECHNOLOGY


Department of Electrical & Computer Engineering

❖ Course No: ECE-1204


❖ Course Title: Object Oriented Programming Sessional.

❖ Assignment No: 01,02,03,04


❖ Assignment Topic: Class and object.

❖ Submitted To:

Sagor Chondro Bakchy

Lecturer

Dept. of ECE, RUET

❖ Submitted By:

Adittya Podder

Roll: 1910045

Year: 1st (EVEN)

❖ Date of Experiment: 20.1.2021

❖ Date of Submission: 22.1.2021

1|Page
❖ Assignment No: 01

❖ Assignment Name: Determine a given number is prime or not using class and object.

❖ Input: (Code)

#include<iostream>
#include<stdio.h>
using namespace std;
class A
{
int n, count;
public:
void input()
{
cout<< " Enter any number";
cin>>n;
}
void output ()

{
count=0;
for (int i=1; i<=n; i++)
{
if(n%i==0)
{
count++;
}
}
if (count==2)
cout<<"prime number";
else
cout<<"Not prime number";
}

};

int main ()
{

2|Page
A obj;
obj. input ();
obj. output ();
}

❖ Output:

❖ Assignment No: 02

❖ Assignment Name: Find all the prime numbers in the range 1000.

❖ Input: (Code)

#include<iostream>
using namespace std;
class checkPrime
{
int n, i, flag, arr [1000] = {};
public:

void output () {

3|Page
for (n=2; n<=1000; n++) {
flag=0;
for (i=2; i<=n/2; i++) {

if(n%i==0) {

flag=1;
break;
}
}
if(flag==0) {

arr[n]=n;

}
}
cout<<"Prime numbers between 1 to 1000 are: "<<endl<<endl;
for (i=0; i<=1000; i++) {
if(arr[i]!= 0)
cout<<arr[i]<<" ";
}
}
};
int main ()
{
checkPrime obj;
obj.output();
return 0;
}

❖ Output:

4|Page
❖ Assignment No: 03

❖ Assignment Name: Find prime numbers in an interval a and b input by user.

❖ Input: (Code)

#include<iostream>
using namespace std;
class checkPrime
{
int n, a, b, i, flag, arr [1000] = {};
public:
void input () {
cout<<"Enter 2 numbers: "<<endl;
cin>>a>>b;
}
public:
void output () {
for (n=a; n<=b; n++) {
flag=0;
for (i=2; i<=n/2; i++) {

if(n%i==0) {

flag=1;
break;
}
}
if(flag==0) {

arr[n]=n;

5|Page
}
}
cout<<"\nPrime numbers are: "<<endl<<endl;
for (i=0; i<=1000; i++) {
if(arr[i]>1)
cout<<arr[i]<<" ";
}
}
};
int main ()
{
checkPrime obj;
obj.input();
obj.output();
return 0;
}

❖ Output:

❖ Assignment No: 04

❖ Assignment Name: Find summation of all the numbers obtained in problem-3.

6|Page
❖ Input: (Code)

#include<iostream>

using namespace std;

class checkPrime

int n, a, b, i, flag, arr [1000] = {};

public:

void input () {

cout<<"Enter 2 numbers: "<<endl;

cin>>a>>b;

public:

void output () {

for (n=a; n<=b; n++) {

flag=0;

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

if(n%i==0) {

flag=1;

break;

7|Page
}

if(flag==0) {

arr[n]=n;

int sum=0;

cout<<"Sum of the prime numbers are: ";

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

if(arr[i]>1)

sum=sum+arr[i];

cout<<sum;

};

int main ()

checkPrime obj;

obj.input();

obj.output();

return 0;

8|Page
❖ Output:

9|Page

You might also like