Question

In: Computer Science

Write a simple C program to generate a chart of circle properties. Output chart “iteration” is...

Write a simple C program to generate a chart of circle properties. Output chart “iteration” is to be specified by user input. Your chart will include the radius, diameter, circumference, and Area values in a single table, and radius values will range from 0 to 50, floating point values, with three-decimal-place precision. Table should have all column entries right-justified and each column will have a heading above the entries. For example, assuming user enters a incrementation value of 5, the first few entries of the table could look something like:

Radius Diameter Circumference Area

———————————————————————

0.000 0.000 0.000 0.000

5.000 10.000 31.416 78.540

10.000 20.000 62.832 314.159

Use right alignment using printf() Diameter, Circumference, and Area must be used as functions. Output a blank line after every 10 radius entries.

C language Thanks!

Solutions

Expert Solution

//---------------- radius_chart.c ---------

#include<stdio.h>
//constant to define for PI VALUE
#define PI 3.14
//FUNCTION that returns the diameter for given radius.
float getDiameter(float radius)
{
   return 2 * radius;
}
//FUNCTION that returns the area for given radius.
float getArea(float radius)
{
   return PI * radius * radius;
}
//FUNCTION that returns the circumference for given radius.
float getCircum(float radius)
{
   return 2 * PI * radius;
}
//FUNCTION that prints the chart for given radius.
void printChart(float incRadius)
{
   //variables to store
   float area;
   float circum;
   float diameter;
   float range = 50.0;
   float radius;
   printf("\n Radius Diameter Circumference Area\n");
   printf("\n------------------------------------------------------\n");
   //from radius 0 to 50(range) increment by incRadius entered by user.
   int count = 0;
   for(radius = 0.0; radius <= range;radius += incRadius)
   {
       //get area,circumference and diameter
       area = getArea(radius);
       circum = getCircum(radius);
       diameter = getDiameter(radius);
       //use .3 to round by 3 decimal places, and right align the values
       //that are printed by using a number after %
       printf("%10.3f %10.3f %15.3f %15.3f\n",radius,diameter,circum,area);
       if(count%10 == 0 && count != 0)
       {
           printf("\n");
       }
       count++;
   }
}

int main()
{
  
   float incRadius;
   //get input for incremented radius
   printf("Enter Incrementation Value: ");
   scanf("%f",&incRadius);
   //if it is negative or zero print error msg and exit.
   if(incRadius <=(float) 0)
   {
       printf("Invalid Increment value. It should be >=1\n");
       printf("Exiting....");
       return 1;
   }
   //if not print the chart by passing input from user.
   printChart(incRadius);
   return 0;
}

//PLEASE LIKE THE ANSWER AND COMMENT IF YOU HAVE ANY DOUBTS.


Related Solutions

Write a program in C++ that will output the truth table for a simple wff. There...
Write a program in C++ that will output the truth table for a simple wff. There will only be Ps and Qs, so you can hard code the P truth table and the Q truth table into arrays. The user will use A for ^ , O for V, N for ' , & I for -> . Hint: Read the first character, load the appropriate truth table into the first working array. Read the next character. If it is...
C++ Write a program that reads in two Integers. A starting number and a number of iterations. For each iteration, you generate a new number that is the result of reading off the number of same digits in the original number. output each Iteration
C++ Write a program that reads in two Integers. A starting number and a number of iterations. For each iteration, you generate a new number that is the result of reading off the number of same digits in the original number. output each Iteration.   Example starting number 331 next number [iteration 1]:"2 threes and 1 one" = 231 next number [iteration 2]:"1 two, 1 three, 2 ones" = 121321 next number [iteration 3]: "1 one, 1 two, 1 one,...
Write a C++ program that prompts the user for the radius of a circle and then...
Write a C++ program that prompts the user for the radius of a circle and then calls inline function circleArea to calculate the area of that circle. It should do it repeatedly until the user enters -1. Use the constant value 3.14159 for π Sample: Enter the radius of your circle (-1 to end): 1 Area of circle with radius 1 is 3.14159 Enter the radius of your circle (-1 to end): 2 Area of circle with radius 2 is...
Write a program in C that computes the area of a circle (Area = pi *...
Write a program in C that computes the area of a circle (Area = pi * r2) and the volume of a sphere (Volume = 4/3 * pi * r3). Both formulas use r which is the radius. Declare a float variable pi = 3.14159. Get the value of r from the keyboard and store it in a float variable. Display both the area of the circle and the volume of the sphere.
Write a C program to store the parameters of a circle on a 2D plane: the...
Write a C program to store the parameters of a circle on a 2D plane: the x and y coordinates of the center point and r, the radius. All three parameters are real (floating point) numbers. -Define a type to store the parameters of a circle. Write a function that receives the parameters of two circles as function parameters, and returns whether the two circles overlap or not. (Two circles overlap if the distance between their center points - computed...
Write c code program for the following Write a function, circle, which takes the radius of...
Write c code program for the following Write a function, circle, which takes the radius of a circle from the main function and assign the area of the circle to the variable, area, and the perimeter of the circle to the variable, perimeter. Hint: The function should have three variables as input. Since the contents of the variables are to be modified by a function, it is necessary to use pointers. Please type out the full usable program. Thank you.
C++ Visual Studio 2019 Part A : Program Description: Write a program to generate a report...
C++ Visual Studio 2019 Part A : Program Description: Write a program to generate a report based on input received from a text file. Suppose the input text file student_grades.txt contains the student’s Last name , First name, SSN, Test1, Test2, Test3 and Test4. (25%) i.e. Alfalfa   Aloysius   123-45-6789 40.0    90.0   100.0    83.0 Generate the output Report File student_final.txt in the following format : LastName FirstName   SSN Test1   Test2   Test3   Test4 Average FinalGrade i.e. Alfalfa   Aloysius   123-45-6789 40.0    90.0   100.0   ...
Write a simple Python program that will generate two random between 1 and 6 ( 1...
Write a simple Python program that will generate two random between 1 and 6 ( 1 and 6 are included). If the sum of the number is grader or equal to 10 programs will display “ YOU WON!!!”. if the sum is less than 10, it will display “YOU LOST”. After this massage program will ask users a question: “if you want to play again enter Y. if you want to exit enter ‘N’) If the user enters Y they...
Write a simple Python program that will generate two random between 1 and 6 ( 1...
Write a simple Python program that will generate two random between 1 and 6 ( 1 and 6 are included). If the sum of the number is grader or equal to 10 programs will display “ YOU WON!!!”. if the sum is less than 10, it will display “YOU LOST”. After this massage program will ask users a question: “if you want to play again enter Y. if you want to exit enter ‘N’) If the user enters Y they...
In java processing 3, write a program that draws a circle. The center of the circle...
In java processing 3, write a program that draws a circle. The center of the circle would be first point on the canvas where the mouse is pressed on it. While the mouse is pressed, the circle can be drawn by moving the mouse cursor farther than the first point that mouse was pressed (circle center). As soon as the code is run, a timer at the bottom of the canvas should start working. Also, the radius of the circle...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT