This lab is due by Wednesday, August 28, 2024, Before Class.
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.
Jump To: Rubric Submission
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 200: 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 (Windows)
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!
>
Running your Code (OS X / *nix)
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.out
Hello world!
>
The Iterative Process
Congratulations! You've written, compiled, and run your very first program!
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:
- Declare & define constants as needed
- Declare & define the appropriate variables that are needed giving them the proper data type, a proper identifier, and a sensible initial value
- You must prompt the user to enter all non-constant values for the equations
- Calculate the right hand side of the equation to solve 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
For now, we will accept the default number of decimal places that are printed to the terminal.
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.
Grading Rubric
Your submission will be graded according to the following rubric:
Points | Requirement Description |
0.70 | Fully meets specifications |
0.15 | Submitted correctly by Wednesday, August 28, 2024, Before Class |
0.15 | Best Practices and Style Guide followed |
1.00 | Total Points |
Lab Submission
Always, always, ALWAYS update the header comments at the top of your main.cpp
file. And if you ever get stuck, remember that there is LOTS of help available.
Zip together your main.cpp, Makefile
file(s) and name the zip file L1A.zip
. Upload this zip file to Canvas under L1A.
This lab is due by Wednesday, August 28, 2024, Before Class.
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.