Skip to main content

Day 1: Introduction to Programming

Summary
We first learned about the different types of applications of programming to various engineering fields. Then we went over the types of computer languages, which included, machine, assembly, and high-level languages. C and C++, the languages used in this course, are both high-level languages. We were introduced to the engineering problem solving methodology, which is as follows:

  1. Problem statement
  2. Input/output description
  3. Hand example
  4. Algorithm development
  5. Test solution
We then did an activity which utilized this. We got together in groups to perform steps 1-3 in trying to find the distance between two points, then tested this on the computer. 

After that, we learned about constants and variables, and about different numeric data types. 

Problems

1

//First day
//Distance formula program
//This program calculates distance between two points

#include <stdio.h>
#include <math.h>

int main(void){
//Declared variables
double x1=2, y1=4, x2=2, y2=4, side1, side2, distance;
//Compute side length
side1=x2-x1;
side2=y2-y1;
//Compute distance between points
distance=sqrt(side1*side1 + side2*side2);
//Print distance between points
printf("The distance between the two points is %5.2f \n",      distance);
return 0;
}





Homework


One meter is equivalent to 0.00062137 miles, and therefore to convert from meters to miles, I simply multiply by this constant. 


I looked up the formula for converting degrees Celsius to  degrees Rankine, and inputted this formula in. This formula would take the inputted value of degrees Celsius and convert it to Rankine when the program is run.


 The area of an ellipse with semi-major axes of length a and b is pi*a*b. I used this formula to calculate my result.

The area of a sector of a circle with an angle d degrees between its radii is pi*r^2 multiplied by d/360, since it is a fraction of a circle, and that fraction can be found by dividing the degrees between the radii by the total number of degrees in a circle. 


Comments

Popular posts from this blog

Day 20: Structures, Programming with Pointers

Lecture Structures Structure defines set of data, but individual parts do not have to be the same type. Example 1.1 struct hurricane {  char name[10];  int year,category; }; Within a structure, variables and even arrays can be defined. Structures are also known as aggregate data types since multiple data values can be collected into a single data type. Individual values within a structure are called data members, and each member is given a name. In Example 1.1, the names of the data members are name, year, and category. To refer to a data member, the structure variable name followed by a period and a data member name is used.  Definition and Initialization Define structure. Keyword struct used to define name of structure (aka structure tag) and data members that are included in structure After structure defined, structure variables can be defined using declaration statements. Semicolon required after structure definition. Statements can appear before m...

Day 6: Analog Sensors | Functions and Modularity

Functions Functions are sets of statements that typically perform operation or compute value. They can help to make programs more accessible and usable for non-programmers e.g. create function that allows user to type "go forward" and move a robot forward. Modules -Functions can be split up into modules, "divide and conquer" -Each module has specific purpose, can be written and tested separately -Smaller than complete solution, therefore testing is easier -Can be used in new problem solutions without being retested -Reduces overall length of program -Allows for increased collaboration; modules can be worked on in parallel Debugging Longer Programs Use a compiler that gives meaningful information about errors. Adding comments around some sections of code can allow for better focus on other parts of the program. Test complicated functions by themselves. Programmer Defined Functions Execution of program always begins with main function. Additional ...

Day 3: Linear Interpolation, Mathematical Functions, and Arduino Buttons

Figure 1.1 Linear interpolation  assumes that a straight line joins two points f(a) and f(c), and that the value of f(b), where b lies between a and c, lies on this line. Figure 1.2 Cubic spline interpolation  is when the points f(a) and f(c) are joined by a cubic polynomial, and the value of f(b), a function of b, which lies between points a and c, lies on this curve. Formula Assumes a<b<c f(b)=f(a)+((b-a)/(c-a))[f(c)-f(a)] Example 1 The data was given, shown in Figure 1.1 at right. Figure 2.1 Example 2 In the example on the left, we used linear interpolation to find the freezing temperature of certain salinities of water. 1. Problem Statement Use linear interpolation to determine the freezing temperature of water with a certain salinity. 2. Input/Output Description Inputs: first salinity, second salinity, first freezing temperature, second freezing temperature, new salinity. Output: new freezing temperature 3. Hand Example See...