Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Const parameter modifiers and overloading operators. Thank you! Code to use: my_int.cc #include #include #include using namespace std; class my_int { public: //********************************************************* //

C++ Const parameter modifiers and overloading operators. Thank you!image text in transcribed

image text in transcribed

Code to use: my_int.cc

#include #include #include using namespace std; class my_int { public: //********************************************************* // Function: my_int // Purpose: Constructor initializes the val to x // Params: x - the value for the val // Calls: none // Uses: none //********************************************************* my_int(int x); //********************************************************* // Function: my_int // Purpose: Constructor initializes the val to 0 // Params: none // Calls: none // Uses: none //********************************************************* my_int(); //********************************************************* // Function: set // Purpose: Sets the val to x // Params: x - the new value for the val // Calls: none // Uses: none //********************************************************* void set(int x); //********************************************************************* // Function: input // Purpose: reads and stores a value from inp. if fin is a input // stream, then fin is already connected to a file.User enters // a value and ask the user to re-enter the data if the // user enters an incorrect value. // Params: inp -- the input stream // Calls: none // Uses: istream //********************************************************************* void input(istream& inp); //********************************************************************* // Function: output // Purpose: display the val on fout. if fout is a output stream // then fout is already connected to a file // Params: fout -- the output stream // Calls: none // Uses: ostream //********************************************************************* void output(ostream& fout) const; //********************************************************* // Function: get_int // Purpose: returns the val // Params: none // Calls: none // Uses: none //********************************************************* int get_int(); private: int val; // Variable to hold value for class }; //********************************************************* // Function: is_prime // Purpose: object num contains a valid positive value // returns true if num is prime; otherwise // returns false // Params: num - the value to be checked for prime // Calls: sqrt // Uses: cmath //********************************************************* bool is_prime(const my_int& num); int main() { my_int value1; value1.input(cin); value1.output(cout); if (is_prime(value1)) cout val; while (val > val; } } //********************************************************* // Function: is_prime // Purpose: object num contains a valid positive value // returns true if num is prime; otherwise // returns false // Params: num - the value to be checked for prime // Calls: sqrt // Uses: cmath //********************************************************* bool is_prime(const my_int& num) { double limit; int n; //divisor bool prime= true; limit = sqrt(static_cast(num.get_int())); n = 2; while (n   C++ Const parameter modifiers, overloading operators, and separate compilation 1 Introduction In this lab, you are going to get some practice using const modifiers, overloading operators as friend functions and in order to define a class so that it is an ADT you need to divide the program into separate files. By doing so the programmers who use the type do not have access to how values and operations are implemented. 1.1 Laboratory Preparation Create a directory called L inside your 2400 directory 2. const Parameter Modifier Purpose of this exercise is for you to experience the problems that you can encounter by inconsistent use of the const modifier parameter (pg,638). First copy the following program below: m int.cc Then read and understand the program. After that compile the program and check the error messages. Answer question #1a on the answer sheet. After correcting the problem recompile and run the program. Answer questions ib-ic on the answer sheet. You can find more information on this topic on pages 638 640 3. overloading operators overload the operator as a friend function to the unvoint class. Include the function declaration and the function definition. Also include the necessary statements in the main to test the function you have written. You will have to create two objects of nvainit type with values you choose. Then compare and see whether you're overloaded operator is working correctly. (Don't make any changes to the existing statements i the main function.. Don't forget to include the documentation for this function. Look at question 1d on the answer sheet for the point distribution. For more information, look at pages 644 646 in your text

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

How Do I Use A Database Research Tools You Can Use

Authors: Laura La Bella

1st Edition

1622753763, 978-1622753765

More Books

Students also viewed these Databases questions

Question

5-3 What are the current trends in computer hardware platforms?

Answered: 1 week ago

Question

1. What is Ebola ? 2.Heart is a muscle? 3. Artificial lighting?

Answered: 1 week ago