Question: IN C++ CODING. Please identifty each task, thank you. In this assignment, you are going to write a program for the following tasks. You must

IN C++ CODING.

Please identifty each task, thank you.

IN C++ CODING. Please identifty each task, thank you. In this assignment,

In this assignment, you are going to write a program for the following tasks. You must submit only a single cpp file. Task 1: write a function that takes input a positive integer int n, and returns a string s The function should store the binary representation of n starting from the most significant bit. (Most significant bit means the left most bit.) For example, if the input is 26, then the function returns the string s = 11010". Here you do not need to worry about the problem of overflow Task 2: write a function that converts a binary number into a decimal number. In particular the function takes input a string s that represents the binary digits from the most significant bit to the least significant bit. Your function returns an integer that is equal to the number s represents. For example, if your string is 11010, your return should be 26. You can assume that there is no overflow Note: if you don't know the "string" type in c++, google it Task 3: In your main function, you should write some test cases to test your Tasks 1 and 2 The format is flexible. In the class, we have discussed about the algorithms. Here is a quick recap. Given a decimal number n, we can represent n into the following way where k is roughly log2(n) and all ai's are binary digits, i.e., either 0 or 1. The binary representation of n should be a^ak-1... ao. If you are given a binary string apak-i... ao (represented by an array), then you can compute n from the above formula directly The slightly more non-trivial part is to to compute the binary digits from n. Here we can first determine the ao by using mod 2. (Think about how and why). Then we know: So we can use the same idea to find out a1. Proceeding in this way, we can find out all the ai's For more information about binary numbers, you can find more details from Wikipedia (http //en.wikipedia.org/wiki/Binary_number)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!