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 :
INPUT :
Input 1 :
Input 2 :
Input 3 :
Input 4 :
OUTPUT :
Output 1 :
Output 2 :
Output 3 :
Output 4 :
help ASAP 3. Write a string C++ function named UnsignedPartialSum() that takes two string parameters 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 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 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, 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 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: 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 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 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 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 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...