Question
help ASAP
3. Write a string C++ function named UnsignedPartialSum() that takes two string parameters and an int parameter. If both stri
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:-

Text Code :

#include <iostream>

#include <string>

#Include <sstream>

using namespace std;

//Function Declaration

string UnsignedPartialSum(string para1,string para2,int num);

//Main driver function

int main() {

//Inputs

string para1=''1101101'';

string para2=''10111'';

int num = 3;

//Output

count << UnsignedPartialSum(para1,para2,num)<<endl;

return 0;

}

//Fumction Definition

string UnsignedPartialSum(string para1,string para2,int num) {

//Necessary Variables

int maxLen = 0, ansMul = 0, numVal,temPara1;

char charVal;

string zero = ''0'' ansFinal ='''';

//Check to see if integer argument passed is positive

if(num < 0) {

return ''Error! Integer Parameter is negative'';

}

//Check to see if parameter 1 is binary or not

for (int i =0; i < para1.Length();i++) {

charVal = para1.at(i);

numVal = charVal-'0';

if (numVal > 1 || numVal < 0) {

return ''Error! para1 is not binary'';

}

}

//check to see if parameter 2 is binary or not

for (int i =0; i < para2.length();i++) {

charVal = para2at(i);

numVal = charVal - ''0'';

if (numVal > 1 || numVal < 0) {

return ''Error! para2 is not a binary'';

}

}

//Calculating maximum length

if (para1.size() > para2.size()) {

maxLen = para1.size();

}else {

maxLen = para2.size();

}

//Calculating final string with answer

stringstream templnt(para1);

templnt >> tempPara1;

charVal = para2.at(num);

numVal = charVal - ''0'' ;

ansMul = numVal * tempPara1;

if (num > 0) {

for (int i = 0; i < (maxLen +1); i++) {

if (i <(maxLen -(num -1))) {

ansFinal + = zero;

} else if (i ==(maxLen -(num -1))) {

ansFinal += to_string(ansMul);

} else {

ansFinal +=Zero;

}

}

if (ansMul ==0) {

for (int i =0;i <(maxLen -1);i++) {

ansFinal + = zero;

}

}

} else {

for (int i =0; i < maxLen; i++) {

ansFinal +=zero;

}

if (ansMul > 0) {

ansFinal +=to_string(ansMul);

}

if (ansMul ==0) {

for (int i = 0; i < (maxLen -1); i++) {

ansFinal +=zero;

}

}

}

return ansFinal;

}

CODE :#include <iostream> #include <string> #include <sstream> using namespace std; //Function Declaration string UnsignedPartialsu//Check to see if Parameter 1 is binary or not fubintem aliminusacal.lengthsmitti charval = paral.at(i); numVal = charVal-aif (num > ) { for (int i = 0; i < (maxLen + 1); i++) { if (i < (maxlen - (num - 1))) { ansFinal += zero; } else if (i == (max

INPUT :

Input 1 :int main() { string paral = 1101101; string para2 = 10111; int num = 3; cout << UnsignedPartialSum(paral, para2, num) <<

Input 2 :int main() { string paral = 1101201; string para2 = 10111; int num = 3; cout << UnsignedPartialSum(paral, para2, num) <<

Input 3 :int main() { string paral = 110101; string para2 = 19121; int num = 3; cout << UnsignedPartialSum(paral, para2, num) << e

Input 4 :int main() { string paral = 110101; string para2 = 10111; int num = -2; cout << UnsignedPartialSum(paral, para2, num) <<

OUTPUT :

Output 1 :<terminated> (exit value: 0) BinaryTestChegg Debug [C/C++ Application] p0000110110100

Output 2 :<terminated> (exit value: 0) BinaryTest Chegg Debug [C/C++ Application) Error! Paral is not a binary

Output 3 :<terminated> (exit value: 0) BinaryTestChegg Debug [C/C++ Application] Error! Para2 is not a binary

Output 4 :<terminated> (exit value: 0) BinaryTestChegg Debug [C/C++ Application) Error! Integer Parameter is negative

Add a comment
Know the answer?
Add Answer to:
help ASAP 3. Write a string C++ function named UnsignedPartialSum() that takes two string parameters and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java arrays Create method named repeatedN that takes two integer parameters named range and n and...

    Java arrays Create method named repeatedN that takes two integer parameters named range and n and returns an integer array Method should return an integer array that has numbers 0 - range repeated in order n times If range is less than or equal to 0; return an array that has 0 repeated n times Create a second method named printArray that takes an integer array as a parameter. The method should print out every element on the same line...

  • Python 3.6 Question 12 (20 points) Write a function named wordLengths. The function wordLengths takes two...

    Python 3.6 Question 12 (20 points) Write a function named wordLengths. The function wordLengths takes two parameters: 1. inFile, a string that is the name of an input file 2. outFile, a string that is the name of an output file The input file exists when wordLengths is called; wordLengths must create the file outFile. The input file contains only letters and white space For each line of the input file, wordLengths should identify the length of the longest word...

  • /* Write a recursive function named editDistance that accepts two string    * parameters and returns...

    /* Write a recursive function named editDistance that accepts two string    * parameters and returns the "edit distance" between the two strings as an    * integer. Edit distance (also called Levenshtein distance) is the minimum    * number of "changes" required to get from s1 to s2 or vice versa. A "change"    * is a) inserting a character,    * b) deleting a character, or    * c) changing a character to a different character.    *...

  • Write a function named insertBeforeKey that takes the parameters as follows list as an char array,...

    Write a function named insertBeforeKey that takes the parameters as follows list as an char array, capacity for the capacity of the array, numItems has the number of items in the array, key is an element of the array before which newVal is to inserted. Assume key is always present in the array. and newVal has the new value to be inserted into the array. If the array is at capacity then the function should return -1, otherwise return 0...

  • Must be C++ 11 Write a function named insertinArray that takes the following parameters: list: an...

    Must be C++ 11 Write a function named insertinArray that takes the following parameters: list: an integer array index: index at which to insert the new item numitems: number of items currently in the array arrayCapacity: capacity of the array newVal: value to insert into the array If the array is at capacity then the function should return-1. Otherwise, insert newVal at index and return O for success int insertInArray(int listl 1, int index, int numItems, int arrayCapacity, int newVal)...

  • Code written in NASM Function called findLargest Write a function called findLargest that receives two parameters:...

    Code written in NASM Function called findLargest Write a function called findLargest that receives two parameters: an unsigned doubleword array and the length of the array. The function must return the value of the largest array member in eax. Preserve all registers (except eax) that are modified by the function. Write a test program in main that calls findLargest three times, each call using a different array with different lengths. Function called countHits Write a function called named countHits that...

  • Write a function template named summarray, with two parameters: and array called are and an int...

    Write a function template named summarray, with two parameters: and array called are and an int holding the number of elements in arr. The function should return the sum of the elements in arr. this template must work for double or int arrays. Show a sample function call to the template function you wrote. What would you have to do to use the templates sumArray function with an array of objects of a custom class?   

  • Lisp program count-of (symbol list): Write a function named count-of that takes two parameters, a symbol...

    Lisp program count-of (symbol list): Write a function named count-of that takes two parameters, a symbol and a list. Count the number of instances of x in the list. Do not count the number of x in any sub-lists within the list. Test: count-of 'a '(a 'a(a c) d c a). Result: 2 trim-to (symbol list): Write a function named trim-to that takes a symbol and list as parameters. Return a new list starting from the first occurrence of the...

  • Write a function named "write_string" that takes no parameters and doesn't return a value. This function...

    Write a function named "write_string" that takes no parameters and doesn't return a value. This function will write the string "hockey" to a file named "sacrifice.txt". If a named "sacrifice.txt" already exists it should be overwritten. (Python) Can you help me?

  • Make a public class called ManyExamples and in the class... Write a function named isEven which...

    Make a public class called ManyExamples and in the class... Write a function named isEven which takes in a single int parameter and returns a boolean. This function should return true if the given int parameter is an even number and false if the parameter is odd. Write a function named close10 which takes two int parameters and returns an int. This function should return whichever parameter value is nearest to the value 10. It should return 0 in the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT