CSCI 261 - Programming Concepts - Maynooth 2022

Lab 1A - Math Equation Solver

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 Ideal Gas Law P = nRT / V
2 Civil Engineering Average Acceleration Average Acceleration a = x - x0 / (t - t0)2
3 Electrical Engineering Ohm's Law Ohms Law I = V / R
4 Engineering Physics Newton's Law of Universal Gravitational Newton's Law of Universal Gravitational F = Gmemm / r2
5 Math Distance Distance d = square root x2 + y2
6 Math Volume Sphere Volume of a Sphere V = 4/3 pi r 3
7 Mechanical Engineering Deflection Deflection
8 Mechanical Engineering Heat Transfer Heat Transfer Q = h A delta T
9 Mechanical Engineering Stress Stress sigma = F / a
10 Mining Shear Stress Shear Stress
11 Physics Coulomb's Law Coulombs Law

For each equation, you must:

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.