Please help solving these following questions:
Convert 18210 into binary (or into hex).
Convert 3276810 into binary (or into hex).
Convert E7A216 into binary or decimal.
Convert 11100101102 into decimal (or into hex).
• Understand or code a function that uses default parameters.
• Describe or use a group of overloaded functions.• Write a function to find the average of a 1-dim array of floats.
• Write a function to multiply two 1-dim arrays together to produce a third array (dot product)(e.g., a[5] = { 10, 20, 30, 40, 50 }; b[5] = { 3, 5, 0, 2, 4 }; compute c[5] = { 30, 100, 0, 80, 200 } ).
• Write a function to convert a cstring array to all lowercase or all uppercase letters(e.g. for example, “CSC 2430 Data Structures” is converted to “csc 2430 data structures”).
• Write a function to remove all blank characters from a cstring array(e.g., “ Here is my String “ “HereismyString” )
• Write a function to copy one cstring array to another cstring array.
• Write a function to convert a cstring array that contains a string of digit characters into thecorresponding integer value (e.g., “1234” gets converted to the int value 1234).- Remember, the character digit ‘5’ can be converted to numeric value (‘5’ – ‘0’), and “1234” means ( ( (1)*10 + 2) * 10 + 3) * 10 + 4which can be computed in a loop.
• Write a function to count the number of “words” in a cstring (where words are separated by blanks)(e.g., “I am Mike, you’re one of my friends.” has 8 words).• Write a function to determine the location of a particular substring value within a larger string(e.g., where is the substring “The” located in the cstring “Hi There” ? answer: position 3).
• Write a function to compare two cstring values to determine which one has the larger alphabeticvalue (e.g., “a” vs “abc”, or “abc” vs “ABC”, or “Hi There” vs “Hello”, or “A1” vs “A23”, etc).
Program :
#include<iostream> #include<cstring> using namespace std; //Default arguments void number_display(int a=0) { cout << "Number : " << a << endl; } //Function Overloading void add(int a, int b) { cout << "Function that determines the sum of two integers" << endl; cout << "Sum of " << a << " and " << b << " is " << a+b << endl; } void add(float a, float b) { cout << "Function that determines the sum of two floats" << endl; cout << "Sum of " << a << " and " << b << " is " << a+b << endl; } void add(float a, float b, int c) { cout << "Function that determines the sum of two floats and an integer" << endl; cout << "Sum of " << a << "," << b <<" and " << c << " is " << a+b+c << endl; } //Average in of 1-Dimensional array of floats float average(float arr[], int n) { float sum=0,avg; int i; //loop through the array for(i=0;i<n;i++) { sum+=arr[i]; //determine sum } //average=sum of numbers / number of numbers avg=sum/n; return avg; } //Multiply two 1-Dimiensional arrays void dot_product(int a[], int b[], int c[], int n) { int i; //loop through the arrays for(i=0;i<n;i++) { //determine the product c[i]=a[i]*b[i]; } } // Convert string from Lowercase to Uppercase and Uppercase to Lowercase void change_case(char *str) { int i; //traverse through the string for(i=0;str[i]!='\0';i++) { //if the character is in upper case, then convert it to lower case if(str[i]>=65 && str[i]<=90) { str[i]=tolower(str[i]); } //if the character is in lower case, then convert it to upper case else if(str[i]>=97 && str[i]<=122) { str[i]=toupper(str[i]); } } } //Remove all blank characters from string void remove_blank(char *str) { int i=0,count=0; //traverse through the string while(str[i]) { //if the character is blank, then increment count if(str[i]==' ' || str[i]=='\t') count++; //else copy the character else str[i-count]=str[i]; //increment i i++; } str[i-count]='\0'; } //Copy one string to another void string_copy(char *str1, char *str2) { int i=-1; //traverse through the string, and copy each character from str1 to str2 for(i=0;str1[i]!='\0';i++) { str2[i]=str1[i]; } //if the 1st string is empty string, then the 2nd string also be empty. if(i==0) str2[0]='\0'; } //Convert string into integer int string_to_integer(char *str) { int n=0,i; //traverse through the string for(i=0;str[i]!='\0';i++) { //logic is in the question n=n*10+(str[i]-'0'); } return n; } //Number of words in a string int words(string str) { int i,count=0; //traverse through the string for(i=0;str[i]!='\0';i++) { //if the character is a blank space, then increment count if((str[i]==' ' || str[i]=='\t') && !(str[i+1]==' ' || str[i+1]=='\t')) { count++; } } //if the string is not empty, then increment count if(count>0) count++; return count; } //Location of particular substring in a string int substring_location(string str, string sstr) { int i,j,loc=-1; //traverse through the string for(i=0;str[i]!='\0';i++) { loc=-2; //if the 1st character of the substring is the character in the String if(sstr[0]==str[i]) { //check if the substring is in the String for(j=1;sstr[j]!='\0';j++) { //if the character in the String doesn't match the character in the String if(sstr[j]!=str[i+j]) { //then, set loc to -1 loc=-1; break; } } //if the substring is present in the String, then set location to index if(loc!=-1) { loc=i; break; } } } return loc; } //Larger alphabetical value void alphabetical_value(string str1,string str2) { int num1, num2, i; //traverse through string1 to determine the sum of the alphabetical value for(i=0;str1[i]!='\0';i++) { num1+=str1[i]; } //traverse through string2 to determine the sum of the alphabetical value for(i=0;str2[i]!='\0';i++) { num2+=str2[i]; } //Compare the alphabetical value of the strings if(num1>num2) cout << str1; else cout << str2; cout << " has larger alphabetical value"; } int main() { cout << "\n********************Default arguments***************************\n"; cout << "When argument is supplied, "; number_display(5); cout << "Default argument, when argument is'nt supplied, "; number_display(); cout << "\n*********************************************************************\n"; cout << "\n********************Function overloading***************************\n"; float f1,f2; int i1,i2; i1=5; i2=6; add(i1,i2); f1=3.2,f2=1.5; add(f1,f2); f1=4.3,f2=0.5, i1=3; add(f1,f2,i1); cout << "\n*********************************************************************\n"; cout << "\n**********Average in of 1-Dimensional array of floats****************\n"; int i,n; cout << "Enter the size of the array : "; cin >> n; float arr[n]; cout << "Enter the array elements : "; for(i=0;i<n;i++) cin >> arr[i]; cout << "Average : " << average(arr,n) << endl; cout << "\n*******************************************************************\n"; cout << "\n**********Multiply two 1-dimensional arrays************************\n"; cout << "Enter the size of the arrays : "; cin >> n; int a[n],b[n],c[n]; cout << "Enter the elements of 1st array A : "; for(i=0;i<n;i++) cin >> a[i]; cout << "Enter the elements of 2nd array B : "; for(i=0;i<n;i++) cin >> b[i]; cout << "The Dot product of the arrays A and B : "; dot_product(a,b,c,n); for(i=0;i<n;i++) cout << c[i] << " "; cout << "\n*******************************************************************\n"; cout << "\n********Lowercase to Uppercase and Uppercase to Lowercase***********\n"; char str[256]; cout << "Enter a string : "; cin.ignore(); cin.getline(str,256); cout << "Before Conversion : " << str << endl; change_case(str); cout << "After Conversion : " << str ; cout << "\n*******************************************************************\n"; cout << "\n********Remove all blank characters from string***********\n"; str; cout << "Enter a string : "; cin.getline(str,256); cout << "Before Conversion : " << str << endl; remove_blank(str); cout << "After Conversion : " << str ; cout << "\n*******************************************************************\n"; cout << "\n********Copy one string to another***********\n"; char str1[256], str2[256]; cout << "Enter a string : "; cin.getline(str1,256); cout << "String 1 : " << str1 << endl; string_copy(str1,str2); cout << "String 2 : " << str2 ; cout << "\n*******************************************************************\n"; cout << "\n********************Convert string into integer********************\n"; int num; cout << "Enter a string to convert into integer : "; cin.getline(str,256); cout << "String : " << str << endl; num=string_to_integer(str); cout << "Integer Number : " << num ; cout << "\n*******************************************************************\n"; cout << "\n***********************Number of words in a string*****************\n"; cout << "Enter a string : "; cin.getline(str,256); num=words(str); cout << "Number of words : " << num ; cout << "\n*******************************************************************\n"; cout << "\n**********Location of particular substring in a string*************\n"; char sstr[256]; cout << "Enter a string : "; cin.getline(str,256); cout << "Enter a substring : "; cin.getline(sstr,256); num=substring_location(str,sstr); if(num<0) cout << "Substring not found.."; else cout << "Substring found at position : " << num; cout << "\n*******************************************************************\n"; cout << "\n***********************Larger alphabetical value*****************\n"; cout << "Enter String 1 : "; cin.getline(str1,256); cout << "Enter String 2 : "; cin.getline(str2,256); alphabetical_value(str1,str2); cout << "\n*******************************************************************\n"; return 0; }
Output:
Please help solving these following questions: Convert 18210 into binary (or into hex). Convert 3276810 into...
I think you are actually doing binary to hex. please do this without loops and you can use recursion. please write a working C code. Thanks Write a loop-less function to convert from Hex to Binary. (HINT: Use a helper function/recursion) binHex[16] [5] {"0000", "O001","0010","0011","0100" ,"0101", "0110", "0111", "1000", "1001" , "1010", "1011", "1100", "1101", "1110" 1 const char = s char hexToBinary ...) 7
Write a VBA code to convert an arbitrary binary integer number to its equivalent decimal number. Specific requirements: Use InputBox function to acquire the input for an arbitrary binary integer number; Convert the binary integer to its equivalent decimal number; Return the decimal number in a message box. Submit your (VBA code) Excel screen shoot. Below functions may be useful in your VBA code: Val( ): can convert a string-type number in ( ) to its numeric value; Len( ):...
ord Paragrapth Styles 1 Perform the following conversions Convert 51 (decimal) to binary and to hex a b. Convert 0xDI (hexadecimal) to binary and to decimal c. Convert Ob11001001 (binary) to hex and to decimal 2. Find the 2's complement of the following 4 bit numbers a 1101 b 0101 3. Perform the following 4 bit unsigned operations. For each, indicate the 4-bet result and the carry bit, and indicate if the answer is correct or not a. 5+8 b....
11.3 LAB: Convert String to Cyphertext cstring mplement the following (Called a Ceasar Cypher, since it was used in Ceasar's time) using this function prototype in the same file char cypher (string str, int rotate); The idea is that you will declare a variable of type string and give it a value in main. Then pass it into the cypher function. Cypher will create a cstring by copying the str to a new char* of size str.size). Remember that you...
Write a C++ program for the instructions below. Please read the instructions carefully and make sure they are followed correctly. please put comment with code! and please do not just copy other solutions. 1. write the code using function 2. Please try to implement a function after the main function and provide prototype before main function. Total Characters in String Array 10 points Problem 2 Declare a string array of size 5. Prompt the user enter five strings that are...
C++ language only. Thank you C++ language (cout <). NO atoi function. And please pay attention to the rules at the bottom. Extra good rating to whoever can help me with this. TIA. In certain programming situations, such as getting information from web forms, via text boxes, the data coming in may need to be numerical (we want to perform arithmetic on it), but it is stored in the form of a list of characters (the numerical value stored is...
C++ code please asap QUESTIONS Write the test main function as described next. This function is NOT a member function of either of the two classes above. It is located in separate source file. Create an array of type Flight and size 10 1. Prompt the user to enter values for speed, name, and id for all 10 objects. You must use the overloaded input stream operator of class Flight. 1. Write the value of the name variable of all...
Note: Please test your output on the console and also avoid the functions below. We were unable to transcribe this image6. Write a function which combines two strings which are passed as 7. The trimLeft) method removes whitespace from the left end of a 8. Write a function which removes whitespace from both ends of the parameters. Mix one character from each string and return the concatenated result. function('ABC','Defg) return ADBeCfg string. Whitespace in this context is all the whitespace...
Hi, I need help writing a program that reads in data (hex, octal or decimal values) from an input file and outputs the values in to another base form (hex, octal,decimal) one line at a time depending on the formatting characters provided by the input file. I am posting the code requirements below and an example of what theinput file will look like and what should be output by the program. I only need the one .cpp program file. Thanks...
I need little help with C language. I need to pass what I get from HexToBin(char* hexdec) into char* input so that what I got there it should pass it as string array parametr. Example: Enter IEEE-Hex: 40200000 Equivalent Binary value is : 01000000001000000000000000000000 Decimal Number: 2.5 #include <stdio.h> void HexToBin(char* hexdec) { long int i = 0; while (hexdec[i]) { switch (hexdec[i]) { case '0': printf("0000"); break;...