0% found this document useful (0 votes)
14 views6 pages

Oops Assignment 3

The document contains three C++ code snippets demonstrating different functionalities. The first snippet defines a class that sets and displays two integer values, the second processes a float number to calculate and display its integer and fractional parts along with their squares, and the third calculates the sum of the digits of a five-digit integer. Each code snippet includes its respective output statements.

Uploaded by

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

Oops Assignment 3

The document contains three C++ code snippets demonstrating different functionalities. The first snippet defines a class that sets and displays two integer values, the second processes a float number to calculate and display its integer and fractional parts along with their squares, and the third calculates the sum of the digits of a five-digit integer. Each code snippet includes its respective output statements.

Uploaded by

bizzylazing
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

OOPS ASSIGNMENT 3

1. #include <iostream>
using namespace std;

class MyClass {
private:
int x;
int y;

void display() {
cout << "x = " << x << ", y = " << y
<< endl;
}

public:
void setValues(int a, int b) {
x = a;
y = b;
display();
}
};

int main() {
MyClass obj;
obj.setValues(10, 20);
return 0;
}

OUTPUT:

2. #include <iostream>
#include <cmath>

using namespace std;

class Number {
private:
int a;
float b;
public:
float c;

void process(float num) {


a = static_cast<int>(floor(num));
b = num - a;

// Calculate squares
float square_num = num * num;
float square_a = a * a;
float square_b = b * b;

c = square_a + square_b;

cout << "Square of number: " <<


square_num << endl;
cout << "Integer part (a): " << a <<
endl;
cout << "Fractional part (b): " << b <<
endl;
cout << "Sum of squares of a and b (c): "
<< c << endl;
}
};

int main() {
float num;
cout << "Enter a float number: ";
cin >> num;

Number obj;
obj.process(num);

return 0;
}

OUTPUT:
3. #include<iostream>
using namespace std;
int main()
{
int n;
cout << "enter n: ";
cin >> n;

int a1,a2,a3,a4,a5;
int sum = 0;

a1=n%10;
n=n/10;
a2=n%10;
n=n/10;
a3=n%10;
n=n/10;
a4=n%10;
n=n/10;
a5=n%10;

sum =a1+a2+a3+a4+a5;
cout << " sum: " << sum << endl;
return 0;
}

OUTPUT:

You might also like