c++代考 – 编程代写 – assignment代写 – CMPT 135
c++代考

c++代考 – 编程代写 – assignment代写 – CMPT 135

CMPT 135  FIC 202101  Assignment 1

 

c++代考 Problem StatementIn this assignment, we will implement a class named Integer that will mimic the C++ int data type. The aim is for us to apply···

 

Instructor: Dr. Yonas T. Weldeselassie (Ph.D.)  c++代考

Problem Statement

In this assignment, we will implement a class named Integer that will mimic the C++ int data type. The aim is for us to apply what we have learned in the course regarding specification, design, implementation, debugging, and testing of C++ classes.

The class specification which describes what we would like to achieve is therefore that. We require our Integer objects to perform all numeric computations just like the int data type in C++. The class declaration is provided for you so that all of us will have the same class design. Your task is to implement the member and friend functions listed inside the class declaration. We also provide a test program and its sample run output that tests the functionality of the Integer class in order to help you test your work.

Discussion  c++代考

We would like our Integer class to represent integer numbers as dynamic array of characters such that. Each element of the array is a digit character (‘0’, ‘1’, ‘2’, …, ‘9’). Moreover the class keeps the sign of the number. And the number of digits in the number using two additional member variables named sign and length respectively. For example, the integer number -5932 will be represented with an Integer object

  • Whosesign member variable is assigned the character value ‘-,
  • Whoselength member variable is assigned the integer value 4, and
  • Whosedynamic array will contain the four character elements ‘5’, ‘9’, ‘3’, and ‘2’. Positive numbers and zero are represented with a ‘+’ sign.

In order to have versatile class design, we provide three constructor member functions. A destructor, an assignment operator, and output stream operator as follows

c++代考

  • Defaultconstructor: Implemented for  Do not modify it.
  • Non-defaultconstructor that takes an int data type argument: constructs Integer object from int
  • Copyconstructor: For copying
  • Destructor:To delete the memory allocated for an object and reset the object to a default
  • Assignmentoperator: To assign an Integer object same data type
  • Outputstream operator: Implemented for  Do not modify it.

Moreover, this design will allow us to assign an int data type value to an Integer object thanks to automatic casting from int data type to Integer data type. Which will be possible thanks to our non-default constructor that takes int data type argument. See Lab Work for Week 3 and Week 4 for more details about automatic casting achieved with non-default constructors.

Restrictions

In this assignment

  • Youare not allowed to add or remove any include directive or namespace to the
  • Youare not allowed to add or remove any member or friend function from the class
  • Youare not allowed to change the signature or access specifier (private or public) of any of the member or friend functions.

Starting Your Work  c++代考

In order for you to easily copy and paste the provided class declaration. And the test program, these code segments are provided in a text file named Starter Code.txt uploaded together with the assignment. You can simply copy and paste the code in this text file into your project. So that you can start your work right away.

Submission Format

You are required to submit one C++ file that contains only your class definition (that is the implementation of all the member and friend functions) through Moodle. A submission link is provided on Moodle together with this assignment. Please do NOT submit the class declaration or the test program code.

Submission Due Date and Time

The assignment due date and time is Sunday 21 February 2021 at 11:55PM PST.

Marking

Your submission will be tested under Microsoft Visual C++ 2010 Express. And you are advised to test your program on the same IDE before submitting your work. A program with any syntax or linking errors will automatically get zero mark. A program with runtime or semantic errors will lose marks depending on how severe its shortcoming is when it is executed.

The provided class declaration contains few private member functions (some static and others not static) that will be extremely useful when we implement the class. Although these member functions can be accessed from within any other member or friend function definitions. They will not however be accessible from outside the class definition because they are private member functions.

These member functions should be implemented with the following specification:

  • voidappendDigit(const char &digit);
    • Thisfunction must add the digit argument at the end of the calling object and adjust the length by incrementing it by 1. It should not modify the sign.
  • voidprependDigit(const char &digit);
    • Thisfunction must add the digit argument at the begining of the calling object and adjust the length by incrementing it by 1. It should not modify the sign.

c++代考

  • voidresize(const int &new_length);
    • This function must first test if the new_length argument is greater than the length of the calling object. If that is true then the function prepends as many as required ‘0’ digits to the calling object until the object’s length becomes equal to the new_length argument. This is same as saying this functionadds leading zeros to the calling.  This will be very useful when we perform arithmetic operations of Integer objects. If the new_length is less than or equal to the calling object’s length. Then this function must return without doing anything.
  • voidtrim();
    • This function should remove any leading zeros from the calling object. And adjust the length accordingly.If the calling object contains all ‘0’ digits, then it must assign the calling object an integer value zero.

c++代考

  • staticint compare_magnitudes(const Integer &A, const Integer &B);
    • This function must compare the magnitudes of the Integer objects A and B (that is their values without considering their sign). And return 0 if they are equal, return 1 if the magnitude of A is greaterthan the magnitude of B. And return -1  This function will be extremely useful when performing arithmetic operations on Integers.
  • staticInteger add_magnitudes(const Integer &A, const Integer &B);
    • Thisfunction must perform the addition operation of the magnitudes of the Integer objects A and B (that is their values without considering their sign). And return an Integer object with appropriate length and a ‘+’ sign. This function does not throw any overflow digit . Because we can always store as many digits as we wish in an Integer object. For example, adding 19 and 98 should return 117. Observe that A and B may have different lengths. When we call this  Thus we may first make copies of the A and B objects. Then use the resize utility member function in order to have the copy objects to have the same lengths. And then perform the addition easily.
  • staticInteger subtract_magnitudes(const Integer &A, const Integer &B);
    • Similarto the addition of magnitudes, this function must perform the subtraction operation (A-B) of the magnitudes of the Integer objects A and B (that is their values without considering their sign). And return an Integer object with appropriate length and a ‘+’ sign. This function must assume a pre-condition that the magnitude of A is greater than the magnitude of B.

Integer Numbers Arithmetic  c++代考

In order not to waste too much time performing unnecessary computations, please first familiarize yourself with the arithmetic of integer numbers using pen and paper. Among other things, you should recall that

  • Thesum of two positive integer numbers can be computed
  • Thesum of two negative numbers is the same as adding their magnitudes (positive values) and then adjusting the sign of the result.
  • Thesum of positive and negative numbers is the same as subtracting the lesser value from the larger and then adjusting the sign of the result.
  • Thedifference of two numbers is the same as adding the left hand side operand with the negative of the right hand side operand.
  • Multiplicationis a repeated addition
  • Divisionoperation is a repeated subtraction
  • Modulooperation is computed using the division, subtraction, and multiplication
  • Divisionoperation whose divisor is zero value should cause runtime

Speed of Computation  c++代考

You will notice that the speed of computations on Integer objects will be very slow. This is fine because we have designed our class to not truncate any overflow digits. If on the other hand we had fixed number of digits. Then the computation speed could have been enhanced much better using static arrays instead of the dynamic arrays that we are using in this assignment.

Moreover, our aim in this assignment is to appreciate the intense of computations that take place inside the computer processor when performing arithmetic operations. Once you are through with this assignment, you may try to comprehend the design of a Double class to represent double data types. And attempt some arithmetic operators overloading to appreciate even more the working principles of a computer.

 

更多代写:java程序代写 Gre代考 lab代写 essay代写  网课代刷 java代写推荐

合作平台:天才代写 幽灵代  写手招聘  paper代写

发表回复