Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search & Filtering

program that computes the area of either a rectangle, a circle or a right-angled triangle. The program should display a menu that enables the user to select the type of figure whose area he/she wants to compute. Depending on the user’s choice, the program should prompt for the dimensions and perform the computations. The output should be: - The type of figure, the dimensions and the area. Define three functions: - one to compute the area of a rectangle, one the area of a circle and one the area of a triangle. NB: 1. The calculation should be for only one figure at any one time.  

 2. Computations should be done in the user-defined functions.

  1. Rewrite the following function so that it does not use any square brackets (not even in the parameter declarations) but does use the integer variable k. Do not use any of the <cstring> functions such as strlen, strcpy, etc.
    // This function searches through str for the character chr.
    // If the chr is found, it returns a pointer into str where
    // the character was first found, otherwise nullptr (not found).

    const char* findTheChar(const char str[], char chr)
    {
        for (int k = 0; str[k] != 0; k++)
            if (str[k] == chr)
                return &str[k];

        return nullptr;
    }
  1. Now rewrite the function shown in the previous so that it uses neither square brackets nor any integer variables. Your new function must not use any local variables other than the parameters. Do not use any of the <cstring> functions such as strlen, strcpy, etc.
  1. Rewrite the following function so that it returns the same result, but does not increment the variable ptr. Your new program must not use any square brackets, but must use an integer variable to visit each double in the array. You may eliminate any unneeded variable.
    double mean(const double* scores, int numScores)
    {
        const double* ptr = scores;
        double tot = 0;
        while (ptr != scores + numScores)
        {
            tot += *ptr;
            ptr++;
        }
        return tot/numScores;
    }

The strequal function is supposed to return true if and only if its two C string arguments have exactly same text. Explain what the problems with the implementation of the function are, and show a way to fix them.

      // return true if two C strings are equal
    bool strequal(const char str1[], const char str2[])
    {
        while (str1 != 0  &&  str2 != 0)  // zero bytes at ends
        {
            if (str1 != str2)  // compare corresponding characters
                return false;
            str1++;            // advance to the next character
            str2++;
        }
        return str1 == str2;   // both ended at same time?
    }

    int main()
    {
        char a[15] = "Wang, A.";
        char b[15] = "Wang, R.";

        if (strequal(a,b))
            cout << "They're the same person!\n";
    }

The computeCube function is correct, but the main function has a problem. Explain why it may not work and show a way to fix it. Your fix must be to the main function only; you must not change computeCube in any way.

    void computeCube(int n, int* ncubed)
    {
        *ncubed = n * n * n;
    }

    int main()
    {
        int* ptr;
        computeCube(5, ptr);
        cout << "Five cubed is " << *ptr << endl;
    }

This program is supposed to write 30 20 10, one per line. Find all of the bugs and show a fixed version of the program:

    int main()
    {
        int arr[3] = { 5, 10, 15 };
        int* ptr = arr;

        *ptr = 30;          // set arr[0] to 30
        *ptr + 1 = 20;      // set arr[1] to 20
        ptr += 2;
        ptr[0] = 10;        // set arr[2] to 10

        while (ptr >= arr)
        {
            ptr--;
            cout << *ptr << endl;    // print values
        }
    }

What does the following program print and why? Be sure to explain why each line of output prints the way it does

    #include <iostream>
    using namespace std;

    int* maxwell(int* a, int* b)
    {
        if (*a > *b)
            return a;
        else
            return b;
    }

    void swap1(int* a, int* b)
    {
        int* temp = a;
        a = b;
        b = temp;
    }

    void swap2(int* a, int* b)
    {
        int temp = *a;
        *a = *b;
        *b = temp;
    }

    int main()
    {
        int array[6] = { 5, 3, 4, 17, 22, 19 };

        int* ptr = maxwell(array, &array[2]);
        *ptr = -1;
        ptr += 2;
        ptr[1] = 9;
        *(array+1) = 79;

        cout << &array[5] - ptr << endl;

        swap1(&array[0], &array[1]);
        swap2(array, &array[2]);

        for (int i = 0; i < 6; i++)
            cout << array[i] << endl;
    } 

Make a surprise list with the elements "Groucho," "Chico," and "Harpo."


Create a program that will accept positive or negative number and store it to a list. Accepting input will stop when empty input is encountered. Count and display all positive and negative number input and its index number in the list. Count and display all even and odd positive numbers and its index number. Exclude 0 input.

 

Example:

 

number 1: 78

number 2: 91

number 3: -5

number 4: 0

number 4: 8

number 5: -100

number 6: -2

number 7: 100

number 8:

 

There are 4 positive numbers

All positive numbers: 78 91 8 100

Positive numbers can be found at index number: 0 1 3 6

There are 3 negative numbers

All negative numbers: -5 -100 -2

Negative numbers can be found at index number: 2 4 5

There are 3 positive even numbers

Positive even numbers are: 78 8 100

Positive even numbers can be found at index: 0 3 6

There are 1 positive odd numbers

Positive odd numbers are: 91

Positive odd numbers can be found at index: 1


Create a program that will accept a string. Count the length of the string and convert all vowels to upper case and all consonants to lower case. Count number of vowels and consonants in the string. Display all vowels and consonant characters found in the string and the index number of each vowel and consonant character.


Example:


Enter a string: the quick brown fox


String length is 19

Converted string in upper case and lower case: thE qUIck brOwn fOx


There are 5 vowels

Vowel characters are: e u i o o

Vowel characters can be found at index: 2 5 6 12 17


There are 11 consonants characters.

Consonant characters are: t h q c k b r w n f x

Consonant characters can be found at index: 0 1 4 7 8 10 11 13 14 16 18



LATEST TUTORIALS
APPROVED BY CLIENTS