0% found this document useful (0 votes)
17 views

Lab 10

The document provides instructions for two programming exercises. The first asks students to create a Complex class to represent complex numbers with real and imaginary attributes and methods to initialize and print them. The second asks students to create a Box class to represent boxes with width, length, height attributes and methods to initialize, calculate volume, and identify if it is a cube or cuboid.

Uploaded by

Arda Baran
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)
17 views

Lab 10

The document provides instructions for two programming exercises. The first asks students to create a Complex class to represent complex numbers with real and imaginary attributes and methods to initialize and print them. The second asks students to create a Box class to represent boxes with width, length, height attributes and methods to initialize, calculate volume, and identify if it is a cube or cuboid.

Uploaded by

Arda Baran
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/ 2

Computer Engineering Department

Lab Assignment 10
2022 Fall, CMPE 113 Fundamentals of Programming I

Question 1

A complex number is a number of the form 𝑎 + 𝑏𝑖, where a and b are real numbers.

In this exercise, you’re required to define a class Complex. The class has:

 Attributes: real and imag (both double type)


 A function void init(double re, double img) that initializes the attributes of complex number. It takes
two arguments, and sets the real and imaginary attributes accordingly.
 A void print() method that prints the complex number in usual form. e.g. 5+3i, 4-3i, -2+5i etc.

The main function is already given, as you define the Complex class, the main should function accordingly.

Sample Run:

Enter a complex number: 4.2 5.5

The complex number is: 4.2+5.5i

Enter a complex number: 2 -8

The complex number is: 2.0-8.0i

1
Computer Engineering Department

Question 2:

In this exercise, you’re required to define a class Box. It has:

 Attributes: width, length and height (all int type)


 A function void init(int w, int l, int h) that initializes width, length and height attributes of box.
 A void print() method that prints the volume of box. It also prints whether it’s a cube or cuboid. If all
the sides are same, it prints it’s a cube, otherwise it’s a cuboid.

The main function is already given, as you define the Box class, the main should function accordingly.

Sample run:

Enter box dimensions: 5 4 6

The volume of box: 120

It's a Cuboid

Enter box dimensions: 8 8 8

The volume of box: 512

It's a Cube

You might also like