Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

create the following functions IN C++ that validate input. Each should accept on

ID: 3670884 • Letter: C

Question

create the following functions IN C++ that validate input. Each should accept only values indicated. If the input is incorrect the function should throw an exception. The exception will not be caught in the function.

You will create a function that reads in 2 integer values. One is a number that will be raised to the power of the second. So if 5 and 6 are entered the result would be 5 to the 6th power. If an invalid input is received take appropriate action in response to the exception.

You will create a second function that reads in 2 strings and returns a string where the second is concatenated (appended) to the second. Validate the input and generate an appropriate message in response to any exception. Each input string may contain blank space characters. Your program should call the power function and the concatenation function, handle any exception(s), and display the results.

Explanation / Answer

#include <iostream>

#include <cmath>

using namespace std;

int main() {

    int num1;

    int num2;

    cout << "Enter base and exponent respectively: ";

    cin >> num1 >> num2;

   cout << "Result = " << pow(num1, num2);

    return 0;

}

#include <stdio.h>

#include <string.h>

void main()

{

    char string1[20], string2[20];

    int i, j, pos;

    /* Initialize the string to NULL values */

    memset(string1, 0, 20);

    memset(string2, 0, 20);

    printf("Enter the first string : ");

    scanf("%s", string1);

    printf("Enter the second string: ");

    scanf("%s", string2);

    printf("First string = %s ", string1);

    printf("Second string = %s ", string2);

    /* Concate the second string to the end of the first string */

    for (i = 0; string1[i] != ''; i++)

    {

        /* null statement: simply traversing the string1 */

        ;

    }

    pos = i;

    for (j = 0; string2[j] != ''; i++)

    {

        string1[i] = string2[j++];

    }

    /* set the last character of string1 to NULL */

    string1[i] = '';

    printf("Concatenated string = %s ", string1);

}