CSCI 240 Spring 2024

Assignment 1
Using cout/cin and Arithmetic
(50 points)


Due: Friday, January 26 on Blackboard by 11:59 PM

Overview

For this assignment, write a C++ program to calculate and display the gravitational force between two objects.

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 values 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.)

Ask the user of the program for the mass (in kilograms) of the first object. This value should be saved in a float or double variable.

Ask the user of the program for the mass (in kilograms) of the second object. This value should be saved in a float or double variable.

Ask the user of the program for the distance (in meters) between the two objects. This value should be saved in a float or double variable.

Use the three variables from above to calculate the gravitational force between the two objects (formula follows). Depending on how the code is written, if the calculated gravitational force is saved in a variable, it should be type float or double.

The gravitational force is calculated as:

F = G m1 m2 / distance2

where:

Finally, display the gravitational force with a label that indicates what the value represents.

Program Requirements

  1. At the top of the C++ source code, include a documentation box that resembles the following, making sure to put your name after the "Name" label, the section of CSCI 240 that you're enrolled 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.

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

    /***************************************************************
    CSCI 240         Program 1     Spring 2024
    
    Name:
    
    Section:
    
    Date Due:
    
    Purpose: The purpose of this program is to calculate and display
             the gravitational force between two objects.
    
             The user provides the mass of the two objects and the
             distance between the objects.
    ***************************************************************/
    
  3. Include the following lines of code BELOW the documentation box:

  4. #include <iostream>
    #include <iomanip>
    
    using namespace std;
  5. Use the data types specified above for the two masses, distance, and (if used) the calculated gravitational force. Use variable names that clearly indicate the values that they're holding.

  6. Test the program with values other than the ones supplied in the sample output.

  7. Hand in a copy of the source code (the .cpp file) on Blackboard.

Output:

A single run of the program should resemble the following. The red values in the output are the values entered when the program is run/executed.

****************************************
     Gravitational Force Calculator
****************************************

Enter the mass of object 1 (in kilograms): 70
Enter the mass of object 2 (in kilograms): 80
Enter the distance between the 2 objects (in meters): 1


The force of gravitational attraction is: 3.7352e-007 newtons.

Or

****************************************
     Gravitational Force Calculator
****************************************

Enter the mass of object 1 (in kilograms): 97.5
Enter the mass of object 2 (in kilograms): 12.3
Enter the distance between the 2 objects (in meters): 6.4


The force of gravitational attraction is: 1.95288e-009 newtons.