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

Identify and correct the errors, if there are any, in the following program segm

ID: 674293 • Letter: I

Question

Identify and correct the errors, if there are any, in the following program segments. Briefly why. int func (double a); int func (int a) { return 10 * ar } int func (int a); return 2*ar } func (2, 3); void func (int a); int func1 (int a) { int b; b = 2*a; return b; } void func1 (int a) { return 2*ar double sum(double a, double b) { return a*b; } void func (double a, double b) { double sum; sum = sum (a, b); } Calculate the values of the following function using a C function at x = 1.5. y1 (x) = 2x sin(x) + cos(x) + 4x+3/3x^2+2x+4 Write a program that calculates the area and perimeter of a rectangle. The area and perimeter are calculated using two separate functions, which both take two arguments of double type for width and length of the rectangle. Calculate the area and perimeter using these two functions in the main program for a rectangle with width and length of 2 cm and 5.5 cm, respectively. Write a C program that uses the function rand{} to generate an integer randomly in the range of 1 to 50. The random number generated by the program shall be different at each run. The program then prompts the user to guess the number by displaying the following messages: I have a number between 1-50. Can you guess what it is? Enter your initial guess. After the user's initial guess, the program should display one of the following responses: Correct ! That's the number. Would you like to play again (y or n)? Too low. Guess again. Too high. Guess again. The program should loop until the user guesses the correct answer. Use the 'Too low' and 'Too high' messages to help the user guess the number. Once the user guesses the right number, the program should ask whether he/she would like to play again. Describe your algorithm in procedures, pseudocode, and flowchart.

Explanation / Answer

Finding Area and Perimeter using two different Functions:
#include <stdio.h>
float areaofrec( float length, float width);
float periofrec(float length, float width);
int main ()
{
/* variable definition: */
int menuSelect, intValue;
float length, width;
float result = 0;
// While a positive number
while (intValue > 0)
{
printf ("Enter a positive Integer to calculate the area or perimeter; ");
printf ("OR a negative Integer to exit the program.: ");
scanf(" %d", &intValue);
if (intValue > 0)
{
printf ("Enter 1 to calculate area, 2 to Calculate the perimeter: ");
scanf(" %d", &menuSelect);
if (menuSelect == 1)
{
// Call the area function
printf("You chose to calculate the area of the rectangle! ");
printf(" Please enter the length of the rectangle: ");
scanf(" %f ", &length);
printf(" Please enter the width of the rectangle: ");
scanf(" %f", &width);
result = areaofrec(length, width);
printf("The area of the rectangle is %.0f ", &result);
}
else if (menuSelect == 2)
{
// Call the perimeter function
printf("You chose to calculate the perimeter of the rectangle! ");
printf(" Please enter the length of the rectangle");
scanf(" %f ", &length);
printf(" Please enter the width of the rectangle:");
scanf(" %f", &width);
result = periofrec(length, width);
printf("The area of the rectangle is %.0f ", &result);
}
else
printf("Invalid menu item, only 1 or 2 is accepted ");
}
}
return 0;
}
/* function returning the area of a number */
float areaofrec( float length,float width)
{
return length*width;
}
/* function returning the perimeter of a number */
float periofrec( float length, float width)
{
return (length*2)+(width*2);
}


In C:
#include<stdio.h>
   #include<stdlib.h>
   #include<time.h>
int main ()
   {
int number, input;
/* initialize random seed: */
srand ( time(NULL) );
/* Generate a random number: */
number = rand() % 10 + 1;
do {
printf ("Guess the number (1 to 10): ");
scanf ("%d",&input);
if (number > input)
printf ("The number is higher ");
} while (number!=input);
printf ("That is correct! ");
return 0;
}

In C++:

#include<iostream>
using namespace std;
int randomnumber();
int main()
{
int i;
cout<<"ten random numbers for the range 0 to 50"<<endl;
for(i=0;i<10;i++)
{
randomnumber();
  
}
cin.get();
}
int randomnumber()
{
int j;
j = rand();
if (!(j >= 50))
{
if (!(j<=0))
{
cout<< j<<" ";
}
}
else {randomnumber();}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote