Write a C++ program that simulate a menu based binary number calculator.You don't have to write the main part of the program just the two functions for my C++ program. I wanted to post the sample code from my class but it won't allow me it's too long. This calculate shall have the following five functionalities:
// precondition: s is a string that consists of only 0s and 1s that is at most 16 bits
// postcondition: a 16 bit string has been returned as signed extension of s. For instane,
// if s = "0101" then return value will be "00000000000000000101" total 12
// 0s are added in front of s
// precondition: s is a string that consists of only 0s and 1s
// postcondition: two's complement of s is returned as an 16 bits binary integer. For
// instance, if s = "1101", then return value will be "1111111111111101"
The following functionality has been provided. Please notice that three functions from Project One are provided. The idea is your new function will somehow call corresponding one in these three functions to do the work:
// precondition: b is a string that consists of only 0s and 1s
// postcondition: the positive decimal integer that is represented by b
// precondition: n is a positive integer
// postcondition: n’s binary representation is returned as a string of 0s and 1s
// precondition: b1 and b2 are strings that consists of 0s and 1s, i.e. b1 and b2 are binary
// representations of two positive integers
// postcondition: the sum of b1 and b2 is returned. For instance, if b1 = “11”, b2 = “01”, // then the return value is “100”
Here's the sample code already given I only need help implementing the
using namespace std;
string signed_extension(string s) {
// you implement this one first
return "0";
}
int binary_to_decimal_signed(string s) {
// you implement this one third
return 0;
}
string decimal_to_binary_signed(int n) {
// you implement this one fourth
return "0";
}
string add_binaries_signed(string b1, string b2) {
// you implement this one fifth
return "0";
}
string twos_complement(string s) {
// you implement this one second
return "0";
}
-----------------------------------------------string signed_extension(string b);-------------------------------------
string signed_extension(string b){
//find the length
int number_of_bits=b.length();
//to store new string
string signed_extension_b="";
//if positive
if(b[0]=='0'){
//extending the bits
for(int
i=0;i<(16-number_of_bits);i++){
signed_extension_b=signed_extension_b+'0';
}
signed_extension_b=signed_extension_b+b;
return
signed_extension_b;
}
//if negative
if(b[0]=='1'){
for(int
i=0;i<(16-number_of_bits);i++){
signed_extension_b=signed_extension_b+'1';
}
signed_extension_b=signed_extension_b+b;
return
signed_extension_b;
}
}
----------------------------------------------string twos_complement(string s);-----------------------------------------------
string twos_complement(string s){
//s should be at most 16 bits
int number_of_bits=s.length();
string ones_complement="";
string twos_complement_new="";
string twos_complement_new_temp="";
string binary_in16bit_form="";
//conversion to 16 bits
if(number_of_bits<16){
/*updated
*/
binary_in16bit_form=s=signed_extension(s);
}
else{
binary_in16bit_form=s;
}
//find 1s complement
for(int i=0;i<16;i++){
//finding the
complement
ones_complement+=(binary_in16bit_form[i]=='0')?'1':'0';
}
twos_complement_new_temp=ones_complement;
//finding 2s complement
//adding 1 to 1s complement
twos_complement_new_temp=twos_complement_new=add_binaries(ones_complement,"1");
//updated
if(twos_complement_new_temp.length()>16){
//makes it
16bit
twos_complement_new="";
for(int
i=1;i<twos_complement_new_temp.length();i++){
twos_complement_new+=twos_complement_new_temp[i];
}
}
return
twos_complement_new;
}
Write a C++ program that simulate a menu based binary number calculator.You don't have to write the main part of the...
Write a C/C++ program that simulate a menu based binary number calculator. This calculate shall have the following three functionalities: Covert a binary string to corresponding positive integers Convert a positive integer to its binary representation Add two binary numbers, both numbers are represented as a string of 0s and 1s To reduce student work load, a start file CSCIProjOneHandout.cpp is given. In this file, the structure of the program has been established. The students only need to implement the...
Implement a Java method named addBinary() that takes two String arguments (each representing a binary value) and returns a new String corresponding to the result of performing binary addition on those arguments. Before you begin, if one of the arguments is shorter than the other, call your pad() method from the previous step to extend it to the desired length. Note: ped() method is public static String pad(String input, int size) { if(input.length()>=size) { return input; } String a =...
Needed in C please Write the implementation file, priority_queue.c, for the interface in the given header file, priority_queue.h. Turn in your priority_queue.c file and a suitable main program, main.c, that tests the opaque object. priority_queue.h is attached as a file to this assignment but is also listed here for your convenience. Your implementation file should implement the priority queue using a heap data structure. Submissions that implement the priority queue without using a heap will not receive any credit. #ifndef...
(C++) Two stacks of the same type are the same if they have the same number of elements and their elements at the corresponding positions are the same. Overload the relational operator == for the class stackType that returns true if two stacks of the same type are the same; it returns false otherwise. Also, write the definition of the function template to overload this operator. Write a program to test the various overloaded operators and functions of classstackType. **Please...
I need this to be in C Write the implementation file, priority queue.c, for the interface in the given header file, priority queue.h. Turn in your priority queue.c file and a suitable main program, main.c, that tests the opaque object. priority queue.h is attached as a file to this assignment but is also listed here for your convenience. Your implementation file should implement the priority queue using a heap data structure. Submissions that implement the priority queue without using a...
Complete an Array-Based implementation of the ADT List including a main method and show that the ADT List works. Draw a class diagram of the ADT List __________________________________________ public interface IntegerListInterface{ public boolean isEmpty(); //Determines whether a list is empty. //Precondition: None. //Postcondition: Returns true if the list is empty, //otherwise returns false. //Throws: None. public int size(); // Determines the length of a list. // Precondition: None. // Postcondition: Returns the number of items in this IntegerList. //Throws: None....
I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that accepts one integer parameter and returns the value raised to the third power as an integer. o Write a method called randominRange that accepts two integer parameters representing a range. The method returns a random integer in the specified range inclusive. 2. o Write a method...
Java Programming Write a program to find the number of comparison using binarySearch and the sequentialSearch algorithms as follows: Suppose list is an array of 2500 elements. 1. Use a random number generator to fill list; 2. Use a sorting algorithm to sort list; 3. Search list for some items as follows: a) Use the binary search algorithm to search list (please work on SearchSortAlgorithms.java and modify the algorithm to count the number of comparisons) b) Use the sequential search...
The purpose of this program is to help reinforce container class concepts and linked list concepts in C++. Specifically, the task is to implement the sequence class using a linked list. You need to use the author's file sequence3.h to create your implementation file named sequence3.cpp. Please make your code as efficient and reusable as possible. Please make sure code can pass any tests. sequence3.h // FILE: sequence3.h // CLASS PROVIDED: sequence (part of the namespace main_savitch_5) // This is...
Use C++! This program uses the class myStack to determine the highest GPA from a list of students with their GPA.The program also outputs the names of the students who received the highest GPA. Redo this program so that it uses the STL list and STL queue! Thank you! HighestGPAData.txt* 3.4 Randy 3.2 Kathy 2.5 Colt 3.4 Tom 3.8 Ron 3.8 Mickey 3.6 Peter 3.5 Donald 3.8 Cindy 3.7 Dome 3.9 Andy 3.8 Fox 3.9 Minnie 2.7 Gilda 3.9 Vinay...