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

CSE1002 Assessment 1 Solution

This document contains an assessment for a problem solving and object oriented programming course. It includes 4 sections (A, B, C, D) with 3 questions each on C++ programming concepts like data types, control structures, functions, classes, and OOP principles. Sample programs are provided as answers for various questions like finding quotient and remainder, converting binary to decimal, checking even-odd numbers, calculating factorials and GCD.
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)
166 views9 pages

CSE1002 Assessment 1 Solution

This document contains an assessment for a problem solving and object oriented programming course. It includes 4 sections (A, B, C, D) with 3 questions each on C++ programming concepts like data types, control structures, functions, classes, and OOP principles. Sample programs are provided as answers for various questions like finding quotient and remainder, converting binary to decimal, checking even-odd numbers, calculating factorials and GCD.
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

CSE-1002- Problem Solving and Object-Oriented Programming

Assessment-1: Sitting Arrangement

Board
C1 C2 C3 C4 C5 C6 C7 C8

19BEC0550

R1 19BEC0427 18BEC0909 19BEC0321 19BEC0581 19BEC0783 19BEC0231 19BEC0694 19BEC0032

R2 19BEC0432 18BML0046 19BEC0332 19BEC0584 19BEC0786 19BEC0233 19BEC0703 19BEC0113

R3 19BEC0380 18BEC0580 19BEC0248 19BEC0499 19BEC0725 19BEC0154 19BEC0636 18BML0105

R4 19BEC0349 17BEC0361 19BEC0236 19BEC0466 19BEC0716 19BEC0152 19BEC0606 18BML0094

R5 19BEC0334 16BEC0363 19BEC0234 19BEC0438 19BEC0710 19BEC0147 19BEC0588 18BML0062

R6 19BEC0406 18BEC0991 19BEC0282 18BIS0137 19BEC0774 19BEC0227 19BEC0683 18BML0119

R7 19BEC0363 18BEC0327 19BEC0247 19BEC0483 19BEC0724 19BEC0153 19BEC0610 18BML0101

R8 19BEC0386 18BML0054 19BEC0269 19BEC0540 19BEC0729 19BEC0162 19BEC0669 18BML0107

C1 C2 C3 C4 C5 C6 C7 C8

R1 A B C D A B C D

R2 C D A B C D A B

R3 A B C D A B C D

R4 C D A B C D A B

R5 A B C D A B C D

R6 C D A B C D A B

R7 A B C D A B C D

R8 C D A B C D A B
CSE-1002- Problem Solving and Object-Oriented Programming
Assessment-1 A
Sr.No. Questions Marks

A.1 Why C++ called Middle Level Language? 2

• Low Level Programming


Machine Level Coding
System Software – Device Drivers
• High Level Programming
Hardware Independent Software
Application Software

A.2 C++ Program to Find Quotient and Remainder. 4

#include "CSE1002.h"
//#include <iostream>
using namespace std;

int main()
{
int divisor, dividend, quotient, remainder;

cout << "Enter dividend: ";


cin >> dividend;

cout << "Enter divisor: ";


cin >> divisor;

quotient = dividend / divisor;


remainder = dividend % divisor;

cout << "Quotient = " << quotient << endl;


cout << "Remainder = " << remainder;

return 0;
}

A.3 Program to Convert Binary Number to Decimal. 4

#include "CSE1002.h"
//#include <iostream>
//#include <cmath>

using namespace std;

int convertBinaryToDecimal(long long);

int main()
{
long long n;
cout << "Enter a binary number: ";
cin >> n;

cout << n << " in binary = " << convertBinaryToDecimal(n) << " in
decimal";
return 0;
}

int convertBinaryToDecimal(long long n)


{
int decimalNumber = 0, i = 0, remainder;
while (n!=0)
{
remainder = n%10;
n /= 10;
decimalNumber += remainder*pow(2,i);
++i;
}
return decimalNumber;
}
CSE-1002- Problem Solving and Object-Oriented Programming
Assessment-1 B
Sr.No. Questions Marks

B.1 How many types of constant in C++? Define each type with at least three examples. 2

Primary
• Integer
• Real
• Char
Secondary
• Array
• String
• Pointer
• Union
• Structure
• Enumerator
• Class

B.2 C++ Program to Check Whether Number is Even or Odd. 4

#include "CSE1002.h"
//#include <iostream>
//using namespace std;

int main()
{
int n;

cout << "Enter an integer: ";


cin >> n;

if ( n % 2 == 0)
cout << n << " is even.";
else
cout << n << " is odd.";

// (n % 2 == 0) ? cout << n << " is even." : cout << n << " is


odd.";

return 0;
}

B.3 C++ Program to Find H.C.F. Using Recursion. 4

#include "CSE1002.h"
//#include <iostream>
//using namespace std;

int hcf(int n1, int n2);


int main()
{
int n1, n2;

cout << "Enter two positive integers: ";


cin >> n1 >> n2;

cout << "H.C.F of " << n1 << " & " << n2 << " is: " << hcf(n1,
n2);

return 0;
}

int hcf(int n1, int n2)


{
if (n2 != 0)
return hcf(n2, n1 % n2);
else
return n1;
}
CSE-1002- Problem Solving and Object-Oriented Programming
Assessment-1 C
Sr.No. Questions Marks

C.1 Write any 4 key principles of OOP. 2

1. Encapsulation
2. Data Hiding
3. Abstraction
4. Polymorphism
5. Inheritance

C.2 C++ Program to Find Factorial of user input number. 4

#include "CSE1002.h"
//#include<iostream>
//using namespace std;

int factorial(int n);

int main()
{
int n;

cout << "Enter a positive integer: ";


cin >> n;

cout << "Factorial of " << n << " = " << factorial(n);

return 0;
}

int factorial(int n)
{
if(n > 1)
return n * factorial(n - 1);
else
return 1;
}

C.3 C++ Program to Check Whether a Number is Palindrome or Not. 4

#include "CSE1002.h"
//#include <iostream>
//using namespace std;

int main()
{
int n, num, digit, rev = 0;

cout << "Enter a positive number: ";


cin >> num;
n = num;

do
{
digit = num % 10;
rev = (rev * 10) + digit;
num = num / 10;
} while (num != 0);

cout << " The reverse of the number is: " << rev << endl;

if (n == rev)
cout << " The number is a palindrome.";
else
cout << " The number is not a palindrome.";

return 0;
}
CSE-1002- Problem Solving and Object-Oriented Programming
Assessment-1 D
Sr.No. Questions Marks

D.1 What is the range of signed and unsigned type? 2

Unsigned
0 to (2n-1)

Signed
-2(n-1) to (2(n-1)-1)

D.2 C++ Program to Find GCD using for loop 4

Using while loop:

#include "CSE1002.h"
//#include <iostream>
//using namespace std;

int main()
{
int n1, n2;

cout << "Enter two numbers: ";


cin >> n1 >> n2;

while(n1 != n2)
{
if(n1 > n2)
n1 -= n2;
else
n2 -= n1;
}

cout << "HCF = " << n1;


return 0;
}

Using for loop:

#include "CSE1002.h"
//#include <iostream>
//using namespace std;

int main()
{
int n1, n2, hcf;
cout << "Enter two numbers: ";
cin >> n1 >> n2;

// Swapping variables n1 and n2 if n2 is greater than n1.


if ( n2 > n1)
{
int temp = n2;
n2 = n1;
n1 = temp;
}

for (int i = 1; i <= n2; ++i)


{
if (n1 % i == 0 && n2 % i ==0)
{
hcf = i;
}
}

cout << "HCF = " << hcf;


return 0;
}

D.3 C++ Program to Display Factors of a Number. 4

#include "CSE1002.h"
//#include <iostream>
//using namespace std;

int main()
{
int n, i;

cout << "Enter a positive integer: ";


cin >> n;

cout << "Factors of " << n << " are: " << endl;
for(i = 1; i <= n; ++i)
{
if(n % i == 0)
cout << i << endl;
}

return 0;
}//

You might also like