Pages

Ethics Presentation

NSPE Code of Ethics for Engineers - link

National Society of Professional Engineers
  • This is one of the documents used for interpreting ethical dilemmas submitted by engineers, public officials, and members of the public. 
  • Use this code to analyze your / engineering ethics case study.  Consider the possible ethics violations, then argue the innocence or guilt of the engineers involved.  What principles were violated? What steps were taken to prevent future failures?
NSPE Board of Ethical Review - link 

Assignment:

  • Imagine you are on the NSPE Board of Ethical Review.  Read through a few previously addressed Ethics cases:
specific cases:
Fill in the short form for access to cases.
http://www.nspe.org/resources/ethics/ethics-resources/board-of-ethical-review-cases#2014

then-

See also:
Risk management: 

Space program accidents: 


As a group, or individually, create a 5 minute long video outlining your chosen engineering ethics case.


 Engineering Case Study Presentation:  

1. Cite the disaster or product recall that you decided to investigate.


2. Briefly list (in bullet form) the facts about the incident.


3. List the ethical issues involved, and prioritize these issues from most critical to least critical.


4. How was the case resolved in real life?  (ie, who lost their job, how much $ were the victims paid, what new regulations were imposed, etc.) Do you agree with outcome on your case?  Should more have been done? less?  Support your answer by citing relevant sections in the Code of Ethics, and through using background info on the resolution of other similar cases.


5. Discuss this case from the perspective of :


a.) The public

b) The company managers

c) The company employees

 6. After this incident was resolved, if you were an authority figure for the company, what steps would you take to ensure future ethics violations would not occur?  


7.  Think about what ethical issues might come up in your chosen field of work.  How do you plan on addressing these issues?  If you find yourself in a dangerous working environment or involved with a project that is taking a bad turn - who can you go to for help?

8. Create a Fault or Event tree of the event.  What risk control measures were taken?  What should have been done?
http://intro1201.blogspot.com/2015/11/risk-management.html




Example presentation:



Note the clear concise slides with large font.  Do not paste your entire report onto your slides, just outline the main points!

Use Large clear images. 
A slide with only one clear image is better than a cluttered slide with a bunch of text and multiple images.  The audience's attention should be on the presenter, not distracted by trying to read and figure out cluttered slides.



Presenters knew the material well enough that they were able to discuss the below images without the need to read text off of slides, so they did not need to clutter the below slides with explanatory text. 



There is probably a little too much text on these two slides, but they still contain good information.




What is the difference between plagiarism and research?
Research work has references - and uses more than one reference!  A common practice is to reserve the last slide for references, "thank you" to contributing groups and people, acknowledgement of companies involved, etc. 

Excel VBA

Excel VBA:
  Create your own functions and Basic codes in Excel!

VBA - Visual Basic for Applications
Macros - short programs or sets of recorded keystrokes

Two ways to create a Macro in Excel:
1. Record a set of keystrokes
2. write a VBA subprogram


Excercise #1: Record a set of keystrokes
Open up the circuits Macro-Lab from D2L:
  • MeyersMacroEx.xlsm
  • Enable editing
  • Enable Macros




Click on the "Developer" tab.
If the developer tab is not showing up in your ribbon:
(you might have a different version of excel, but it will be something similar to -
File→Options→Advanced→Customize Ribbon→Main Tabs


Have a look around in the Developer tab
 - hold your curser over an icon to see what it does.

Create a Macro program by recording your keystrokes:

Set up your cell referencing:
  • Absolute referencing - if your calculations come from a stationary cell like "A3" etc. that will never change.
  • Relative referencing - if your calculations will be made relative to a given cell - example, "in the cell to the right of the currently selected cell"
We are going to use relative referencing.  Select the yellow cell as the place everything else will be referenced from:

Click on the Developer tab
Click on the yellow cell
Click on "Use Relative References"


Now, select "Record Macro"
Name your Macro "Series", set up a shortcut key of "S", add description of what your program will do "Macro to calculate voltage drops and current for 3 resistors connected in series"


Once you hit "OK" the Macro will start recording everything that you do.
Fill in the first table just like you did for the lab.  When you are done, hit "Stop Recording"

Note: 
Do not use dollar signs in your macro ($F$8) etc. as this will not allow you to use relative referencing for new tables.

Enter each new equation by hand rather than copy/paste.


"Stop Recording" when you are done filling in your table.

Once you have created your Series Macro, try it out on the second table:
Click on the "Series Macro Starting Cell:
Enter your shortcut key "Cntr + s"
Did it fill in the table in for you?


You can also run your Macro from the ribbon:
Select your starting reference cell
hit "Macros"
Find the Macros you just made
hit "run" to run your program
hit "Edit" to view the VBA code

Click on "Edit" and have a look at the code that was generated from how you filled in your table:


Sub Series()
'
' Series Macro
' Macro to calculate voltage drops and current for 3 resistors in series.
'
' Keyboard Shortcut: Ctrl+s
'
'lines that start with ' are comment lines.  This is not part of the code, it just explains to other users what the program does.

    ActiveCell.Offset(4, 4).Range("A1").Select
    ActiveCell.FormulaR1C1 = "=RC[-3]+RC[-2]+RC[-1]"

The first thing I did was to calculate the total resistance. 
From the starting cell, I moved down 4, and over 4 (4,4)
Then I entered an equation in the new active cell → Row one Column one (R1C1)
I grabbed the cell in the same Row, 3 columns to the left (RC[-3]) added it to RC[-2] and so on

    ActiveCell.Offset(-1, 0).Range("A1").Select
    ActiveCell.FormulaR1C1 = "=R[-1]C/R[1]C"

Next I moved up one row, stayed in the same column, ActiveCell.Offset(-1, 0)  and calculated the current from the cells above and below where the new active cell is "=R[-1]C/R[1]C:

Read through the rest of your code, do you recognize what each line is doing?

    ActiveCell.Offset(0, -1).Range("A1").Select
    ActiveCell.FormulaR1C1 = "=RC[1]"
    ActiveCell.Offset(0, -1).Range("A1").Select
    ActiveCell.FormulaR1C1 = "=RC[1]"
    ActiveCell.Offset(0, -1).Range("A1").Select
    ActiveCell.FormulaR1C1 = "=RC[1]"
    ActiveCell.Offset(-1, 0).Range("A1").Select
    ActiveCell.FormulaR1C1 = "=R[1]C*R[2]C"
    ActiveCell.Offset(0, 1).Range("A1").Select
    ActiveCell.FormulaR1C1 = "=R[1]C*R[2]C"
    ActiveCell.Offset(0, 1).Range("A1").Select
    ActiveCell.FormulaR1C1 = "=R[1]C*R[2]C"
    ActiveCell.Offset(4, -3).Range("A1").Select
    Application.Run "'circuits Macro-Lab.xlsx'!Series"
    ActiveCell.Offset(0, 10).Range("A1").Select
    ActiveWindow.Zoom = 115
    ActiveWindow.Zoom = 130
    ActiveWindow.Zoom = 145
    ActiveWindow.Zoom = 160
    ActiveWindow.SmallScroll Down:=-6
    ActiveCell.Offset(-6, -10).Range("A1").Select
    Application.Goto Reference:="Series"
End Sub

Create Macros for the Parallel and Combined tables just like you created it for the series tables.

Save your file as a Macros enabled workbook, and email me your file:
File→ Save As→ Save as Type→ Excel Macro-Enabled workbook *.xlsm


Video: https://www.youtube.com/watch?time_continue=1&v=Hxgxv2vvGz8 

```````````````````````````````````````````````````````````````````````````````

Recall: Two ways to create a Macro in Excel:
1. Record a set of keystrokes
2. write a VBA subprogram

Let's try out #2.

Start in the Hello Sheet and look around.  Click on the buttons to see what they do!


Create a new Sheet to make your own "Hello" program


+ to add a sheet
Double click on the sheet to rename it. 


Create a "Hello" Button:
Insert → Button


There are two types of buttons:
  • Form Control - simpler, easier to use, but limited
  • ActiveX Controls - Allows you to control more properties
Choose an "ActiveX" button so that you can change the color etc.


 Click and drag on the screen to place the button.

Select "Design Mode:


 Select, then right click your button to:
  • Edit the text: Command Button Object - Edit
  • Change the "properties" (font color, background color color),
  • View your code




Right click and "View Code" or Double click on the button to view code
Type in some code to make the button do something when you click on it, like write "Hello World" into cell D12
Range("D12").Value = "Hello world!"
Range("D13").Value = "How are you today?"
Press F5 key to run your code, or click the green arrow.
Close your editor window, and return to your excel sheet.
Erase the text your program created, click on the button, test it to make sure it is working ok.
Add some more buttons:

Do you remember how to format the font, text, and color of your buttons?
Design mode →right click!


Add some more code to each of your new buttons:

If OptionButton1.Value = True Then Range("D23").Value = "I'm happy to hear you are doing well!"
or
If OptionButton2.Value = True Then  Range("D23").Value = "So sorry to hear you are not doing well."
Note:  You can change your font style for each cell from the home tab

Save your work as a macro enabled worksheet:













Look through the programs in the other sheets:

Edit the below Meyer's personality test to write out your star trek character!
see:
http://randommization.com/2013/12/10/myers-briggs-personality-type-matched-star-wars-star-trek-characters/

Go to the Meyer's sheet
Open up the code by click on "Macros" in the Developer ribbon
"Step into" any of the Macros
Click through the different modules until you find the personality type program




Read through the personality code, can you figure out what it is doing?
Can you edit this program to also display Star Trek Characters?


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub Button2_Click()
Dim Muppet As Variant
Range("B18").Value = "Your Personality type is:"

If Range("B6").Value > Range("B7").Value Then
Range("C19").Value = "E"
Else
Range("C19").Value = "I"
End If

If Range("B9").Value > Range("B10").Value Then
Range("D19").Value = "S"
Else
Range("D19").Value = "N"
End If

If Range("B12").Value > Range("B13").Value Then
Range("E19").Value = "T"
Else
Range("E19").Value = "F"
End If

If Range("B15").Value > Range("B16").Value Then
Range("F19").Value = "J"
Else
Range("F19").Value = "P"
End If

Range("B18").Value = "Your personality type is:"
Range("B21").Value = "Your Star Wars Character is:"
Range("B23").Value = "Your Harry Potter Character is:"
Range("B26").Value = "Your Lord of the Rings Character is:"
Range("B29").Value = "Your Star Trek Character is:"

'ISTJ
If Range("C19").Value = "I" And Range("D19").Value = "S" And Range("E19").Value = "T" And Range("F19").Value = "J" Then
Range("C20").Value = "The Duty FulFiller - Serious and quiet, interested in security and peaceful living. Extremely thorough, responsible, and dependable. Well-developed powers of concentration. Usually interested in supporting and promoting traditions and establishments. Well-organized and hard working, they work steadily towards identified goals. They can usually accomplish any task once they have set their mind to it. "
Range("C22").Value = "Owen Lars"
Range("C24").Value = "Severus Snape"
Range("C27").Value = "Aragorn"
Range("C30").Value = ""
End If

'ISTP
If Range("C19").Value = "I" And Range("D19").Value = "S" And Range("E19").Value = "T" And Range("F19").Value = "P" Then
Range("C20").Value = "The Mechanic - Quiet and reserved, interested in how and why things work. Excellent skills with mechanical things. Risk-takers who they live for the moment. Usually interested in and talented at extreme sports. Uncomplicated in their desires. Loyal to their peers and to their internal value systems, but not overly concerned with respecting laws and rules if they get in the way of getting something done. Detached and analytical, they excel at finding solutions to practical problems. "
Range("C22").Value = "Chewbacca"
Range("C24").Value = "Harry Potter"
Range("C27").Value = "Eowyn"
Range("C30").Value = ""
End If

'ISFJ
If Range("C19").Value = "I" And Range("D19").Value = "S" And Range("E19").Value = "F" And Range("F19").Value = "J" Then
Range("C20").Value = "The Nurturer- Quiet, kind, and conscientious. Can be depended on to follow through. Usually puts the needs of others above their own needs. Stable and practical, they value security and traditions. Well-developed sense of space and function. Rich inner world of observations about people. Extremely perceptive of other's feelings. Interested in serving others."
Range("C22").Value = "C-3PO"
Range("C24").Value = "Neville Longbottom"
Range("C27").Value = "Samwise"
Range("C30").Value = ""
End If

'ISFP
If Range("C19").Value = "I" And Range("D19").Value = "S" And Range("E19").Value = "F" And Range("F19").Value = "P" Then
Range("C20").Value = "The Artist - Quiet, serious, sensitive and kind. Do not like conflict, and not likely to do things which may generate conflict. Loyal and faithful. Extremely well-developed senses, and aesthetic appreciation for beauty. Not interested in leading or controlling others. Flexible and open-minded. Likely to be original and creative. Enjoy the present moment."
Range("C221").Value = "Bail Organa"
Range("C24").Value = "Rubeus Hagrid"
Range("C27").Value = "Legolas"
Range("C30").Value = ""
End If

'INFJ
If Range("C19").Value = "I" And Range("D19").Value = "N" And Range("E19").Value = "F" And Range("F19").Value = "J" Then
Range("C20").Value = "The Protector - Quietly forceful, original, and sensitive. Tend to stick to things until they are done. Extremely intuitive about people, and concerned for their feelings. Well-developed value systems which they strictly adhere to. Well-respected for their perserverence in doing the right thing. Likely to be individualistic, rather than leading or following. "
Range("C22").Value = "Obi-Wan Kenobi"
Range("C24").Value = "Remus Lupin"
Range("C27").Value = "Galadriel"
Range("C30").Value = ""
End If

'INTJ
If Range("C19").Value = "I" And Range("D19").Value = "N" And Range("E19").Value = "T" And Range("F19").Value = "J" Then
Range("C20").Value = "The Scientist - Independent, original, analytical, and determined. Have an exceptional ability to turn theories into solid plans of action. Highly value knowledge, competence, and structure. Driven to derive meaning from their visions. Long-range thinkers. Have very high standards for their performance, and the performance of others. Natural leaders, but will follow if they trust existing leaders. "
Range("C22").Value = "Palpatine"
Range("C24").Value = "Draco Malfoy"
Range("C27").Value = "Elrond"
Range("C30").Value = ""
End If

'INTP
If Range("C19").Value = "I" And Range("D19").Value = "N" And Range("E19").Value = "T" And Range("F19").Value = "P" Then
Range("C20").Value = "The Thinker - Logical, original, creative thinkers. Can become very excited about theories and ideas. Exceptionally capable and driven to turn theories into clear understandings. Highly value knowledge, competence and logic. Quiet and reserved, hard to get to know well. Individualistic, having no interest in leading or following others. "
Range("C22").Value = "Yoda"
Range("C24").Value = "Hermione Granger"
Range("C27").Value = "Gandalf"
Range("C30").Value = ""
End If

'INFP
If Range("C19").Value = "I" And Range("D19").Value = "N" And Range("E19").Value = "F" And Range("F19").Value = "P" Then
Range("C20").Value = "The Idealist - Quiet, reflective, and idealistic. Interested in serving humanity. Well-developed value system, which they strive to live in accordance with. Extremely loyal. Adaptable and laid-back unless a strongly-held value is threatened. Usually talented writers. Mentally quick, and able to see possibilities. Interested in understanding and helping people. "
Range("C22").Value = "Luke Skywalker"
Range("C24").Value = "Luna Lovegood"
Range("C27").Value = "Frodo"
Range("C30").Value = ""
End If

'ESTP
If Range("C19").Value = "E" And Range("D19").Value = "S" And Range("E19").Value = "T" And Range("F19").Value = "P" Then
Range("C20").Value = "The Doer - Friendly, adaptable, action-oriented. Doers who are focused on immediate results. Living in the here-and-now, they're risk-takers who live fast-paced lifestyles. Impatient with long explanations. Extremely loyal to their peers, but not usually respectful of laws and rules if they get in the way of getting things done. Great people skills."
Range("C22").Value = "Han Solo"
Range("C24").Value = "Ginny Weasley"
Range("C27").Value = "Gimli"
Range("C30").Value = ""
End If

'ESFP
If Range("C19").Value = "E" And Range("D19").Value = "S" And Range("E19").Value = "F" And Range("F19").Value = "P" Then
Range("C20").Value = "Wicket: The Performer - People-oriented and fun-loving, they make things more fun for others by their enjoyment. Living for the moment, they love new experiences. They dislike theory and impersonal analysis. Interested in serving others. Likely to be the center of attention in social situations. Well-developed common sense and practical ability. "
Range("C22").Value = "Wicket"
Range("C24").Value = "Fred and George Weasley"
Range("C27").Value = "Pippin"
Range("C30").Value = ""
End If

'ENFP
If Range("C19").Value = "E" And Range("D19").Value = "N" And Range("E19").Value = "F" And Range("F19").Value = "P" Then
Range("C20").Value = "Qui-Gon Jinn: The Inspirer - Enthusiastic, idealistic, and creative. Able to do almost anything that interests them. Great people skills. Need to live life in accordance with their inner values. Excited by new ideas, but bored with details. Open-minded and flexible, with a broad range of interests and abilities"
Range("C22").Value = "Qui-Gon Jinn"
Range("C24").Value = "Ron Weasley"
Range("C27").Value = "Arwen"
Range("C30").Value = ""
End If

'ENTP
If Range("C19").Value = "E" And Range("D19").Value = "N" And Range("E19").Value = "T" And Range("F19").Value = "P" Then
Range("C20").Value = "R2-D2: The Visionary - Creative, resourceful, and intellectually quick. Good at a broad range of things. Enjoy debating issues, and may be into one-up-manship. They get very excited about new ideas and projects, but may neglect the more routine aspects of life. Generally outspoken and assertive. They enjoy people and are stimulating company. Excellent ability to understand concepts and apply logic to find solutions. "
Range("C22").Value = "R2-D2"
Range("C24").Value = "Sirius Black"
Range("C27").Value = "Merry"
Range("C30").Value = ""
End If

'ESTJ
If Range("C19").Value = "E" And Range("D19").Value = "S" And Range("E19").Value = "T" And Range("F19").Value = "J" Then
Range("C20").Value = "Darth Vader: The Guardian - Practical, traditional, and organized. Likely to be athletic. Not interested in theory or abstraction unless they see the practical application. Have clear visions of the way things should be. Loyal and hard-working. Like to be in charge. Exceptionally capable in organizing and running activities. Good citizens who value security and peaceful living. "
Range("C22").Value = "Darth Vader"
Range("C24").Value = "Minerva McGonagall"
Range("C27").Value = "Boromir"
Range("C30").Value = ""
End If

'ESFJ
If Range("C19").Value = "E" And Range("D19").Value = "S" And Range("E19").Value = "F" And Range("F19").Value = "J" Then
Range("C20").Value = "Jar Jar Binks: The Caregiver - Warm-hearted, popular, and conscientious. Tend to put the needs of others over their own needs. Feel strong sense of responsibility and duty. Value traditions and security. Interested in serving others. Need positive reinforcement to feel good about themselves. Well-developed sense of space and function."
Range("C22").Value = "Jar Jar Binks"
Range("C24").Value = "Lily Evans-Potter"
Range("C27").Value = "Bilbo"
Range("C30").Value = ""
End If

'ENFJ
If Range("C19").Value = "E" And Range("D19").Value = "N" And Range("E19").Value = "F" And Range("F19").Value = "J" Then
Range("C20").Value = "Padme Amidala: The Giver - Popular and sensitive, with outstanding people skills. Externally focused, with real concern for how others think and feel. Usually dislike being alone. They see everything from the human angle, and dislike impersonal analysis. Very effective at managing people issues, and leading group discussions. Interested in serving others, and probably place the needs of others over their own needs. "
Range("C22").Value = "Padme Amidala"
Range("C24").Value = "Albus Dumbledore"
Range("C27").Value = "Faramir"
Range("C30").Value = ""
End If

'ENTJ
If Range("C19").Value = "E" And Range("D19").Value = "N" And Range("E19").Value = "T" And Range("F19").Value = "J" Then
Range("C20").Value = "Leia Organa: The Executive - Assertive and outspoken - they are driven to lead. Excellent ability to understand difficult organizational problems and create solid solutions. Intelligent and well-informed, they usually excel at public speaking. They value knowledge and competence, and usually have little patience with inefficiency or disorganization. "
Range("C22").Value = "Leia Organa"
Range("C24").Value = "James Potter"
Range("C27").Value = "Theoden"
Range("C30").Value = ""
End If

End Sub
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Is there a better way to create the above program?
Use the Meyer's program to record each team member's personality type.  Use personality types to help decide what tasks to assign each team member.

Kolb Learning Styles - see Kolb sheet

see:
http://intro1201.blogspot.com/2015/03/jung-meyers-typology-perrys-scheme.html


Look through the Kolb code.
Try out the Kolb Learning styles test.
Record the learning style of everyone in your group.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Example of Creating a Function:


Insert → Module






Public Function Grade(Number As Variant)
   
    If Number > 90 Then
    Grade = "A"
    ElseIf Number > 80 Then
    Grade = "B"
    ElseIf Number > 70 Then
    Grade = "C"
    ElseIf Number > 60 Then
    Grade = "D"
    Else
    Grade = "F"
    End If
      
End Function


Exercise - create a function for curving grades:
Public Function CurvedGrade(Number1 As Variant)

    If Number1 > 85 Then
    CurvedGrade = "A"
    ElseIf Number1 > 75 Then
    CurvedGrade = "B"
    ElseIf Number1> 65 Then
    CurvedGrade = "C"
    ElseIf Number1 > 55 Then
    CurvedGrade = "D"
    Else
    CurvedGrade = "F"
    End If
  
End Function


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Units Example:
Here we have a table where the data changes depending on the units that are selected:

Create a pull down menu with different units:
Data→Data Validation→Data Validation→Allow→List→Source




Subroutine that changes the data to reflect the units that are selected:



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Worksheet.Name = "Sheet3" Then
    If Target.Address = "$B$5" Then
        If Target = "seconds" Then
            c = 1
        ElseIf Target = "minutes" Then
            c = 60
        Else
            c = 3600
        End If
'        k = WorksheetFunction.Count("$B$6:$B$1000")
        k = 126
        j = 6
        Do Until j = k
            Range("$B$" & j).Value = Range("$B$" & j).Value * Range("$O$6").Value / c
        j = j + 1
        Loop
        Range("$O$6").Value = c
        Range("D5").Value = Range("C5").Value & "/" & Range("B5").Value
        Range("E5").Value = Range("C5").Value & "/" & Range("B5").Value & "^2"
       
       
    ElseIf Target.Address = "$C$5" Then
        If Target = "meters" Then
            c = 1
        ElseIf Target = "feet" Then
            c = 3.28084
        End If
'        k = WorksheetFunction.Count("$C$6:$C$1000")
        k = 126
        j = 6
        Do Until j = k
            Range("$C$" & j).Value = Range("$C$" & j).Value * Range("$O$11").Value / c
        j = j + 1
        Loop
        Range("$O$11").Value = c
        Range("D5").Value = Range("C5").Value & "/" & Range("B5").Value
        Range("E5").Value = Range("C5").Value & "/" & Range("B5").Value & "^2"
    End If
        
   
End If
End Sub

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Extra Credit - change the above program to include "miles" under position units.

mini-mester midterm review

What are the 4 components an engineer must balance?
What are heuristics?   
                     

 
How is writing a technical document different than a typical lib arts paper?
          

Understand how to design an experiment:         
http://intro1201.blogspot.com/2015/01/l3-experimental-design.html
                                           
                               
     Statics
Can you draw a free body diagram?  (Just a sketch of your system with forces)  
Can you write out the force balance from the friction lab? 
Where did u = Tan(theta) come from?          

http://intro1201.blogspot.com/2015/01/l4.html
 
History of ENGRing - Name an engineering innovation that changed the world
http://intro1201.blogspot.com/2015/01/chapter-1.html
 

Circuits:  V = iR
Can you sketch out a schematic of 3 resistors in series?  3 resistors in parallel? 
http://intro1201.blogspot.com/2015/02/electricity-static-electricity-surfaces.html
http://intro1201.blogspot.com/2015/02/parallel-and-series-circuits.html

Can you list the 10 step engineering method?  PGR.BAT.DCCR

http://intro1201.blogspot.com/2015/01/l2-engineering-method-chapter-12.html

Teamwork, Project management, & ENGR design:  What are the 5 stages of team formation? 
http://intro1201.blogspot.com/2015/03/teamwork.html
 
Meyers, Perry's:  What is your Meyer's personality type?  Can you briefly discuss the Perry stages?    
http://intro1201.blogspot.com/2015/03/jung-meyers-typology-perrys-scheme.html
 

 Just read through all of the notes, and you will be fine!
 
 

Code::Blocks


Download it for free here:
http://www.codeblocks.org/downloads/26


Open it, choose:
Create a new project → Console application


Open it, choose C++




At School - make a new file in C: to temporarily save your work in:

[...]
Computer - local disk C: - make new folder - codeblocksfiles

Type in a project title (project filename and resulting filename will fill in automatically)



At home: A folder on your desktop might work better



Use all of the defaults for this


Open up Sources→main.cpp

The classic "Hello World" program should already be here for you to do a test build and run with.
First build it by clicking on the yellow gear, then run it by clicking on the green arrow.

Did you get an error?  read the error at the bottom of the screen
It can't find the compiler?
Settings→compiler→Global compiler settings→Toolchain executable→ "Auto Detect" compiler's installation directory

just google whatever errors you find, make sure all of the paths are set up correctly.


Once it is set up correctly, it will compile and you will get a black screen with "Hello World" written on it.



Hello World!

For a description of what all of the lines in your first "hello world" code are doing, read this:
http://www.cplusplus.com/doc/tutorial/program_structure/

The above website is a great resource to give you some basic preliminary tutorials if you are interested in teaching yourself.

Let's add a little more to your program:
~~~~~~~~~~~~~~~~~~~
// operator order
#include <iostream>
using namespace std;

int main ()
{
    cout<<"Hello World!";

  int a, b;         // this declares "a" and "b" as being integers that initially have no assigned value
  a = 8;           // here we assign a the value of 8
  b = 2;            // now b is assigned a value of 2
  a = b;            // just a demo of the importance of order, a is now equal to 2,
  b = 15;            // now a still equals 2, but b has changed to 15.

  cout << "\n a:"<< a;          //cout writes information out to the screen
  cout << "\n b:"<< b<<"\n\n";
}

~~~~~~~~~~~~~~~~~~~~~~~~~~

cout<< "for input and output, see";
http://www.cplusplus.com/doc/tutorial/basic_io/


What if there is an error in your code?


Change "a" to "A" and see what happens when you try to build it:


The red square show you where the error is, and your build messages tell you what the problem is.  If you do not understand the error message, just gooogle it!  In this case, "A" has not been declared - in other words, we did not tell the computer if "A" will store a letter or a number, and if a number what kind of a number - how many bits should it reserve for this information?  If I change "a" to "A" above, I will fix the error:



You can call your variables whatever you want, just be consistent!
Now, try this - change the integer "2" to something with a decimal like "2.315" and see what happens:


Note that the output is still the integer "2" even though it is typed into the program as 2.315.  If we change the variable b from being an integer to holding more information we will have to declare it as something different than an integer, like float:


A list of different types of variables can be found here:
http://www.cplusplus.com/doc/tutorial/variables/



for, if, while...

http://www.cplusplus.com/doc/tutorial/control/

Study this program, and see if you can figure out what it is doing:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//Airplane.cpp : Program to demonstrate for statements.

#include "iostream"
int main(void)
{
   int count;
for(count=1; count<=500;count++)
std::cout<<"I will not throw paper airplanes in class.";

return 0;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
for (initialization; condition; increase) statement;



The point of computer programs - to perform all of those monotonous repetitive tasks we would rather not deal with!

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//bottles of beer song lyrics
#include "iostream"
using namespace std;

int main()
{
int n, c,count;
  cout << "Enter the number of beer bottles you want to start out with" <<"\n";
   cin >>n;

   c=n+1;

for(count=0; count<=n-1; count++)
{    c -= 1;
   cout<<c<<" bottles of beer on the wall "<<c<<" bottles of beer"<<"\n";
   cout<<"take one down, pass it around,"<<c-1<<" bottles of beer on the wall"<<"\n";
   }

return 0;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
see: http://www.cplusplus.com/doc/tutorial/operators/


Class exercise #1:
Modify the below program to write out the Fibonacci series using a for loop:



Just replace "????" with what it needs to be!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//Fibonacci series Program to demonstrate for statements.

#include "iostream"
using namespace std;

int main()
{
int n, a=0,b=1,c,count;
  cout << "Enter the number of terms of Fibonacci series you want" <<"\n";
   cin >>n;

cout<<"1"<<"\n";

for(count=0; count<=n; count++)
{    c = a + b;
         a = ????;
         b = ????;

cout<<c<<"\n";}

return 0;
}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
Class exercise #2:
 
 
Fix the equations in the below program so that it correctly calculates someone's age (slightly different equation if someone has already had their birthday, vs. if they have not had their birthday yet).  
 
Add one more if statement that writes "Happy Birthday!" if currentmonth = birthmonth
 
 

 
// Age Calc.cpp : Program to calculate someone's exact age.
 //
#include <iostream>
#include <conio.h>
#include <time.h>
using namespace std;

 int main()
 
 {
  int birthmonth,birthyear;
int currentmonth,currentyear;
int agey,agem;
cout << "\n\n\t\t\t Age Calculator\n\n";
cout <<"Enter Your Birth Year(Eg:1989):";
cin >>birthyear;
  cout<<"\n\nEnter Your Birth Month(Eg:7):";

 cin>>birthmonth;
  if(birthmonth > 12 || birthmonth < 1)
   return 1;
  time_t t = time(0); // get time now
struct tm * now = localtime( & t );
 currentmonth = (now->tm_mon + 1);
 currentyear = (now->tm_year + 1900);

  if(currentmonth>birthmonth)
{ agey=currentyear-birthyear;
 agem=currentmonth-birthmonth;}

  if(currentmonth<birthmonth)
{agey=currentyear-birthyear;
 agem=currentmonth-birthmonth;}
 
  cout<<"\n\n\t\tYour Age is "<<agey<<" Years And "<<agem<<" Months ";
 _getch();
  return 0;
 }


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Example Codes:

The best way to learn how to program, is to study open source codes.

Can you figure out what each line is doing in the below codes? 
Just google terms you do not understand! 

 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//8-ball program - example of using arrays, rand, and strings

#include <cstdlib>
#include <iostream>
#include <string>
#include <time.h>
 using namespace std;

 const int ARRAY_LENGTH = 6;
 string eightBall[ARRAY_LENGTH];
 bool prgExit = false;



 int main()
 {

    srand ( time(0));
    string userInput;

        eightBall[0] = "No";
        eightBall[1] = "Yes";
        eightBall[2] = "Perhaps...";
        eightBall[3] = "Most definetly yes";
        eightBall[4] = "Almost positively not";
        eightBall[5] = "I think so...";


    cout << "Welcome to the Magic 8-Ball Game!\n";
    cout << "Type a Yes or No question to play, or type 'exit' to quit\n";

    while(!prgExit)

{
            cout << "\nAsk me a question and I will tell the future!\n" ;
              getline(cin, userInput);
         if(userInput.compare("exit") == 0)prgExit=true;
            if(userInput.compare("") != 0 && userInput.compare("exit") != 0){
  
             cout << eightBall[rand()%ARRAY_LENGTH] << "\n";
            userInput = "";
        }
    }

    cout << "Thanks for playing!\n";

    system("PAUSE");
    return EXIT_SUCCESS;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 //hangman game
 #include <iostream>
 #include <cstdlib>
 #include <ctime>
 #include <string>
using namespace std;
const int MAX_TRIES=12;
int letterFill (char, string, string&);
int main ()
 {
 string name;
 char letter;
 int num_of_wrong_guesses=0;
 string word;
 string words[] =
 {
 "United States"
 "india",
 "pakistan",
 "nepal",
 "malaysia",
 "philippines",
 "australia",
 "iran",
 "ethiopia",
 "oman",
 "indonesia"
 };
//choose and copy a word from array of words randomly
 srand(time(NULL));
 int n=rand()% 11;
 word=words[n];
// Initialize the secret word with the * character.
 string unknown(word.length(),'*');
// welcome the user
 cout << "\n\nWelcome to hangman...Guess a country Name";
 cout << "\n\nEach letter is represented by a star.";
 cout << "\n\nYou have to type only one letter in one try";
 cout << "\n\nYou have " << MAX_TRIES << " tries to try and guess the word.";
 cout << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
// Loop until the guesses are used up
 while (num_of_wrong_guesses < MAX_TRIES)
 {
 cout << "\n\n" << unknown;
 cout << "\n\nGuess a letter: ";
 cin >> letter;
 // Fill secret word with letter if the guess is correct,
 // otherwise increment the number of wrong guesses.
 if (letterFill(letter, word, unknown)==0)
 {
 cout << endl << "Whoops! That letter isn't in there!" << endl;
 num_of_wrong_guesses++;
 }
 else
 {
 cout << endl << "You found a letter! Isn't that exciting!" << endl;
 }
 // Tell user how many guesses has left.
 cout << "You have " << MAX_TRIES - num_of_wrong_guesses;
 cout << " guesses left." << endl;
 // Check if user guessed the word.
 if (word==unknown)
 {
 cout << word << endl;
 cout << "Yeah! You got it!";
 break;
 }
}
 if(num_of_wrong_guesses == MAX_TRIES)
 {
 cout << "\nSorry, you lose...you've been hanged." << endl;
 cout << "The word was : " << word << endl;
 }
 cin.ignore();
 cin.get();
 return 0;
 }
/* Take a one character guess and the secret word, and fill in the
 unfinished guessword. Returns number of characters matched.
 Also, returns zero if the character is already guessed. */
int letterFill (char guess, string secretword, string &guessword)
 {
 int i;
 int matches=0;
 int len=secretword.length();
 for (i = 0; i< len; i++)
 {
 // Did we already match this letter in a previous guess?
 if (guess == guessword[i])
 return 0;
 // Is the guess in the secret word?
 if (guess == secretword[i])
 {
 guessword[i] = guess;
 matches++;
 }
 }
 return matches;
 }

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

//tic-tac-toe game
#include< iostream>

using namespace std;

void display_board();
void player_turn();
bool gameover();
//bool - true = 1, false = 0

char turn;
bool draw = false;
char board[3][3] = {{'1', '2', '3'}, {'4', '5', '6'}, {'7', '8', '9'}};

//char = character, used for variables that hold letters like "x"

int main()
{
    cout << "Tic Tac Toe Game\n";
    cout << "Player 1 [X] --- Player 2 [O]\n";
    turn = 'X';

    while (!gameover())
    {
        display_board();
        player_turn();
        gameover();
    }

    if (turn == 'O' && !draw)
    {
        display_board();
        cout << endl << endl << "Player 1 [X] Wins! Game Over!\n";
    }
    else if (turn == 'X' && !draw)
    {
        display_board();
        cout << endl << endl << "Player 2 [O] Wins! Game Over!\n";
    }
    else
    {
        display_board();
        cout << endl << endl <<"It's a draw! Game Over!\n";
    }
}

void display_board()
{
    cout <<"---------------------" << endl << endl;
    cout << "     |     |     " << endl;
    cout << "  " << board[0][0] << "  |  " << board[0][1] << "  |  " << board[0][2] << endl;
    cout << "_____|_____|_____"<< endl;
    cout << "     |     |     " << endl;
    cout << "  " << board[1][0] << "  |  " << board[1][1] << "  |  " << board[1][2] << endl;
    cout << "_____|_____|_____"<< endl;
    cout << "     |     |     " << endl;
    cout << "  " << board[2][0] << "  |  " << board[2][1] << "  |  " << board[2][2] << endl;
    cout << "     |     |     " << endl;
}

void player_turn()
{
    int choice;
    int row = 0, column = 0;

    if (turn == 'X')
    {
        cout << "Player 1 turn [X]: ";
    }
    else if (turn == 'O')
    {
        cout << "Player 2 turn [O]: ";
    }
    cin >> choice;

    switch (choice)
    {
        case 1: row = 0; column = 0; break;
        case 2: row = 0; column = 1; break;
        case 3: row = 0; column = 2; break;
        case 4: row = 1; column = 0; break;
        case 5: row = 1; column = 1; break;
        case 6: row = 1; column = 2; break;
        case 7: row = 2; column = 0; break;
        case 8: row = 2; column = 1; break;
        case 9: row = 2; column = 2; break;
        default:
            cout << "You didn't enter a correct number! Try again\n";
            player_turn();
    }

    if (turn == 'X' && board[row][column] != 'X' && board[row][column] != 'O')
    {
        board[row][column] = 'X';
        turn = 'O';
    }
    else if (turn == 'O' && board[row][column] != 'X' && board[row][column] != 'O')
    {
        board[row][column] = 'O';
        turn = 'X';
    }
    else
    {
        cout << "The cell you chose is used! Try again\n";
        player_turn();
    }

}

bool gameover()
{
    for (int i = 0; i < 3; i++)//Check for a win
    {
        if ((board[i][0] == board[i][1]&& board[i][1] == board[i][2]) || (board[0][i] == board[1][i]&& board[1][i] == board[2][i]) || (board[0][0] == board[1][1]&& board[1][1] == board[2][2]) || (board[0][2] == board[1][1]&& board[1][1] == board[2][0]))
        {
            return true;
        }
    }

    for (int i = 0; i < 3; i++)//Check for draw
    {
        for (int j = 0; j < 3; j++)
        {
            if (board[i][j] != 'X' && board[i][j] != 'O')
            {
                return false;
            }
        }
    }
    draw = true;
    return true;

}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Create a simple code of your own -

Examples:
grade calculator - enter HW grades, have it add them up and average them
circuits: enter resistor values, calculate voltage drops for a series circuit
Friction:  Enter slip angle, calculate friction coefficient - can you find what library file you need to include for this one?