CSCI 240 Spring 2026

Assignment 1
User Input and Arithmetic
(75 points)


Due: Friday, January 23 on the autograder and Blackboard by 11:59 PM

Overview

For this assignment, design a C++ program to calculate the volume and surface area of a sphere.

The cpp file that is submitted for grading must be named assign1.cpp.

Basic Program Logic

The first thing to do in the program is to create any variables that are needed to hold/save information for the program. To determine how many variables are needed, think about the information that will be entered by someone using the program and whether it is important for that information to be saved. Think about any calculations that will be performed by the program and whether the results of the calculations need to be saved. To determine the data type for the variables, think about what type of values that someone using the program will be entering or what kind of results will be produced by any calculations. (Note: to ease into writing this first program, the data type for the variables has been specified below.)

One of the variables used in the program should represent PI. Use the data type float and a value of 3.1415.

Ask the user for the radius of the sphere. This is a value that can have a decimal point and should be saved in a float variable. The prompt to the user must be "What is the radius of the sphere? ". There should be exactly 1 space after the question mark.

Use the radius entered by the user to calculate the volume and surface area of the sphere.

Volume of the Sphere = 4/3 * PI * radius of the sphere3

Surface Area of the Sphere = 4 * PI * radius of the sphere2

When entering the calculation for the sphere volume, don't forget about how C++ will treat the 4/3 portion of the calculation.

Finally, display the calculated volume and surface area in a table as follows:

**********************************************
       Sphere Volume and Area Calculator
**********************************************

Radius:                       [radius]

Volume:                       [volume]
Surface Area:                 [surface area]

where the [radius] is replaced by the sphere radius entered by the user, and [volume] and [surface area] are replaced by the calculated sphere volume and surface area, respectively.

To help with some of the formatting, there should be exactly:

Assignment Requirements

  1. Name the cpp file that is submitted for grading assign1.cpp.

  2. At the top of the C++ source code, include a documentation box that resembles the following, making sure to replace the "Semester" label with the current semester and year, put your name after the "Programmer" label, the section of CSCI 240 that you're in after the "Section" label, and the due date for the program after the "Date Due" label. A box similar to this one will be put in EVERY source code file that is handed in this semester.

  3. DO NOT put this box within cout statements. It should NOT be displayed as part of the output from the program.

    /***************************************************************
    CSCI 240         Assignment 1     Semester
    
    Programmer:
    
    Section:
    
    Date Due:
    
    Purpose: This program calculates and displays the volume and
             surface area of a sphere. The user is prompted for the
             radius of a sphere.
    ***************************************************************/
    
  4. Include line documentation. There is no need to document every single line, but logical "chunks" of code should be preceded by a line or two that describes what the "chunk" of code does. This will be a part of every program that is submitted for the remainder of the semester.

  5. The variable names used in the program must be meaningful.

  6. Make sure to test the program with values other than the ones shown in the output below.

  7. Hand in a copy of the source code (the CPP file) on the autograder and Blackboard.

Output

A few runs of the program should produce the following results:

Run 1

What is the radius of the sphere? 11


**********************************************
       Sphere Volume and Area Calculator
**********************************************

Radius:                       11

Volume:                       5575.12
Surface Area:                 1520.49

Run 2

What is the radius of the sphere? 4.8


**********************************************
       Sphere Volume and Area Calculator
**********************************************

Radius:                       4.8

Volume:                       463.233
Surface Area:                 289.521

When the program is run on the autograder, the output will resemble the following. Notice that the input value is not displayed and there is only one blank line before the first line of asterisks.

What is the radius of the sphere? 

**********************************************
       Sphere Volume and Area Calculator
**********************************************

Radius:                       4.8

Volume:                       463.233
Surface Area:                 289.521