This lab is due by Friday, June 24, 2022, 11:59 PM.
As with all labs you may, and are encouraged, to pair program a solution to this lab. If you choose to pair program a solution, be sure that you individually understand how to generate the correct solution.
Editing A C++ Source Code File
If you haven't already, be sure to create a new folder Set1/L1A
with a file named
main.cpp
.
main.cpp
will contain our
program. You can now start typing code. Sweet! Since this is a
programming class, not a typing class, copy the following starter code between the:
/* CSCI 261 Lab XX (_INSERT_LAB_HERE_): XXXX (_GIVE_BRIEF_DESCRIPTION_HERE_)
*
* Author: XXXX (_INSERT_YOUR_NAME_HERE_)
*
* More complete description here...
*/
// The include section adds extra definitions from the C++ standard library.
#include <iostream> // For cin, cout, etc.
// We will (most of the time) use the standard library namespace in our programs.
using namespace std;
// Define any constants below this comment.
// Must have a function named "main", which is the starting point of a C++ program.
int main() {
/******** INSERT YOUR CODE BELOW HERE ********/
cout << "Hello world!" << endl; // print Hello world! to the screen
/******** INSERT YOUR CODE ABOVE HERE ********/
return 0; // signals the operating system that our program ended OK.
}
Next, edit all places where XXXX
appears in your main.cpp file with the appropriate information. When
you are done, you can save main.cpp
by typing Ctrl + S
.
Running your Code
To compile and execute
your project is a two-step process. Open a terminal, first compile via g++
and then run the
resultant executable:
> g++ main.cpp
> .\a.exe
Hello world!
>
Congratulations! You've written, compiled, and run your very first program!
The Iterative Process
Now that your program is running, we are going to add to the program to perform two calculations. This will be done in two phases, one for each equation.
Equations!
Below are a list of equations provided by previous students. You will write a program to implement two of these equations.
# | Major | Equation | Formula |
1 | Chemistry | Ideal Gas Law | |
2 | Civil Engineering | Average Acceleration | |
3 | Electrical Engineering | Ohm's Law | |
4 | Engineering Physics | Newton's Law of Universal Gravitational | |
5 | Math | Distance | |
6 | Math | Volume Sphere | |
7 | Mechanical Engineering | Deflection | |
8 | Mechanical Engineering | Heat Transfer | |
9 | Mechanical Engineering | Stress | |
10 | Mining | Shear Stress | |
11 | Physics | Coulomb's Law |
For each equation, you must:
- Define the appropriate variables that are needed giving them the proper data type, a proper identifier, and a sensible initial value
- Declare constants as needed
- You must prompt the user to enter all non-constant values for the equations
- Calculate the right hand side of the equation solving for the left hand side
- Print out the final computed value of the equation
- And as always, be sure to be providing helpful output to the user so the user provides the correct values and knows what is being returned
At the end of this lab, your program output should look similar to below (feel free to dress up the messages a bit for this lab):
Enter the acceleration: 4.33
Enter the mass: 9.3
The force is: 40.269
Enter the width: 4
Enter the height: 2
The area is: 8
You just went through a short iterative process, or as programmer's say an incremental build. Once you knew you had your program running properly, you made a small change to the program and reran the program to verify the change was correct. Once again, a small change was introduced to the code and the program was run to verify the proper output. You should become very familiar with this process as it will make future projects go smoother if you make small changes at a time.
Lab Submission
Submit your main.cpp
file(s).
You will submit your solution to this lab with the rest of Set1. Detailed instructions for doing this are posted in Assignment 1.
This lab is due by Friday, June 24, 2022, 11:59 PM.
As with all labs you may, and are encouraged, to pair program a solution to this lab. If you choose to pair program a solution, be sure that you individually understand how to generate the correct solution.