CS 2073 Lab 1: Calculating Diameter, Circumference, and Area of a Circle in C - Prof. Chia, Lab Reports of Computer Science

The instructions for cs 2073 lab 1 at utsa, where students are required to write a c program that reads the radius of a circle and calculates its diameter, circumference, and area. The document also covers input validation and hand-in requirements.

Typology: Lab Reports

Pre 2010

Uploaded on 07/30/2009

koofers-user-6t5
koofers-user-6t5 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 2073 Lab 1: Arithmetic in C
Chia-Tien Dan Lo
Department of Computer Science, UTSA
I Objectives
Demonstrate your ability to read data from the user of your program
Show basic arithmetic operations in C
Use decision structure to filter out invalid inputs
II Hand-in Requirements
All laboratories will be submitted electronically through WebCT. Zip up your entire project folder to submit as the
source. (Right click on the laboratory folder and follow the SentTo link.)
III Details
Write a program that reads in the radius of a circle and prints the circle’s diameter, circumference, and area. Validate
the input ranging from 1 to 100. Any other values should terminate the program. Use the constant value 3.14159
for π. Perform each of these calculations inside the printf statement(s) and use the conversion specifier %f.
IV Setup
1. Project name: Lab1
2. Solution name: MyCPrograms
3. Create a new source with name: main.c
4. Save the source
5. Compile and run the program.
V Coding
1. Write a main function shell just like the Hello World project.
2. Write down comments whenever applicable.
3. Specify a variable radius of type integer
4. Read keyboard input for radius.
Example: To read an integer from keyboard and store it to an integer variable radius
scanf("%d", &radius);
5. If radius is not within [1,100], print a message “Invalid inputs” and terminate the program with a 1” exit
code.
6. Print out diameter with a suitable label.
printf("\nThe diameter is %d\n", 2*radius);
7. Print out circumference and area similar to the previous step.
1
pf2

Partial preview of the text

Download CS 2073 Lab 1: Calculating Diameter, Circumference, and Area of a Circle in C - Prof. Chia and more Lab Reports Computer Science in PDF only on Docsity!

CS 2073 Lab 1: Arithmetic in C

Chia-Tien Dan Lo

Department of Computer Science, UTSA

I Objectives

  • Demonstrate your ability to read data from the user of your program
  • Show basic arithmetic operations in C
  • Use decision structure to filter out invalid inputs

II Hand-in Requirements

All laboratories will be submitted electronically through WebCT. Zip up your entire project folder to submit as the source. (Right click on the laboratory folder and follow the SentTo link.)

III Details

Write a program that reads in the radius of a circle and prints the circle’s diameter, circumference, and area. Validate the input ranging from 1 to 100. Any other values should terminate the program. Use the constant value 3. for π. Perform each of these calculations inside the printf statement(s) and use the conversion specifier %f.

IV Setup

  1. Project name: Lab
  2. Solution name: MyCPrograms
  3. Create a new source with name: main.c
  4. Save the source
  5. Compile and run the program.

V Coding

  1. Write a main function shell just like the Hello World project.
  2. Write down comments whenever applicable.
  3. Specify a variable radius of type integer
  4. Read keyboard input for radius. Example: To read an integer from keyboard and store it to an integer variable radius scanf("%d", &radius);
  5. If radius is not within [1, 100], print a message “Invalid inputs” and terminate the program with a “−1” exit code.
  6. Print out diameter with a suitable label. printf("\nThe diameter is %d\n", 2*radius);
  7. Print out circumference and area similar to the previous step.

1

VI Testing

Compile and run your program until there are no errors.