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

Lab7March Operator Overloading1

The document outlines the requirements for Lab 7, focusing on static members and operator overloading in C++. It details tasks involving the creation of a Distance class and a Matrix class, including constructors, operator overloading, and necessary member functions. Students must submit a Word document with their results, including code and screenshots, while adhering to specific formatting guidelines.

Uploaded by

alimonster105
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)
10 views

Lab7March Operator Overloading1

The document outlines the requirements for Lab 7, focusing on static members and operator overloading in C++. It details tasks involving the creation of a Distance class and a Matrix class, including constructors, operator overloading, and necessary member functions. Students must submit a Word document with their results, including code and screenshots, while adhering to specific formatting guidelines.

Uploaded by

alimonster105
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

Lab 7March2025: Static Members and Operator Overloading

After going through Lab tasks, submit a separate Word document which should

include all the results of the tasks Code should be in word and output should be

screenshot.

First page should contain your Full name, Registration #, Course name and Date

The File Should be saved with your name only.

No copied or AI Should be in Code or Explanation.

Task 1
Write a class Distance that holds distances or measurements expressed in feet and inches.
This class has two private data members: feet: An integer that holds the feet. inches: An
integer that holds the inches.

2.1 Write a constructor with default parameters that initializes each data member of the class. If
inches are greater than equal to 12 then they must be appropriately converted to
corresponding feet

2.2 Generate appropriate getter-setter functions for the data members.


bool setFeet(int f) int getFeet()const bool setInches(int i) It
should ensure proper conversion to feet. int getInches()const
2.3 Define an operator + that overloads the standard + math operator and allows one Distance
object to be added to another.
Distance operator+(const Distance &obj)

2.4 Define an operator- function that overloads the standard - math operator and allows subtracting
one Distance object from another. Distance operator-(const Distance &obj)

2.7 Define an operator= function that overloads the = operator and assign one Distance object to
another. const Distance operator=(const Distance &obj)

2.8 Write main function to test all the implemented functionality.


Task 2
Write a class Matrix. This class has three private data members rows: An integer that
holds the numbers of rows for matrix columns: An integer that holds the
numbers of columns for matrix matrix: An integer pointer to pointer that
points to 2D array (rows x columns).

The class has the following member functions.


Matrix (int r, int c) Constructs a new Matrix object to represent the given
matrix
operator = Overload = operator to assign values
operator == Overload == operator to compare whether matrices are equal
or not
M2=M1+1 Overload + operator which takes integer as argument. It
preforms scalar addition.
M2=M1-4 Overload - operator which takes integer as argument. It
preforms scalar subtraction.
M3=M1+M2 Overload + operator which takes matrix object as argument.
It adds two matrixes and returns the result.
M3=M1-M2 Overload - operator which takes matrix object as argument.
It subtracts two matrixes and returns the result.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy