Monday

Chapt 10.7, 10.8, 10.9 & C++

Just for fun...



10.7 Operating systems
Operating system - interface between computer hardware, software, and user.



Example operating systems:
UNIX
MS-DOS (Microsoft)
Apple - Macintosh

10.9 Example engineering software packages:
Aspen
Simulates processes with continuous flow of material and energy.  (ChemE - Petrolium)
https://www.aspentech.com/Company/About-AspenTech/



  • Define the problem
  • Specify material compositions (nitrogen, methane, steam, etc.)
  • Insert heat exchangers, distillation columns, etc.
  • Define flow rates, temperatures, pressures,
  • Vary operating conditions to see pressures, temps, etc through system. 

GIS
http://www.esri.com/what-is-gis
"
Geographic information system (GIS) lets us visualize, question, analyze, interpret, and understand data"
http://storymaps.arcgis.com/en/


Virtual Instrumentation:

LabVIEW


http://www.ni.com/labview/why/

FEM - finite element




DEM - discrete element (elements are not connected to one another)
.
ANSYS
http://www.ansys.com/


http://www.reactiondesign.com/



SolidWorks
http://www.solidworks.com/


http://www.solidworks.com/sw/products/simulation/plastics.htm?scid=hp_tab_products_plastics



Working Model

http://workingmodel.design-simulation.com/index.php

http://workingmodel.design-simulation.com/WM2D/index.php


http://workingmodel.design-simulation.com/videos/DisplayDDMSE.php?id=14



CAD
Free student download!
http://workingmodel.design-simulation.com/WM2D/index.php






Procedural language: Fortran, Basic, Pascal, C: fetch-and-decode-execute

Value =5
new_value = log(Value)


second line of code – new_value – “fetches” the variable “value”, the log function is “decoded” and then the function log(value) is “executed”.

Object-Oriented Languages:  C++, Java
data and routines that act on data treated as “objects”.  

Value =5
new_value = log(Value)


“value” and “log” are treated as one single object, that, when called, automatically takes the log of value.

object = reusable, modular software component






FORTRAN(77, 90, 95) – Formula translating System, IBM, John Backus – 1957, higher-level programming language that uses English instead of just symbols.
Libraries of FORTRAN codes:
IMSL (International Mathematics and statistics Library)
NAG (Numerical Algorithm group)

.
BASIC – Beginner’s All-Purpose Symbolic Instruction Code – 1964 at Dartmouth by John Kemeny & Kurtz – to encourage more students to use computers by offering a more user friendly, easy-to-learn language. 

.
Pascal – 1971 – also developed for educational purposes by Prf. Wirth (not used much outside of schools)

.
C – 1972 – by Dennis Ritchie of AT&T Bell Labs, outgrowth of BCPL & B languages.

.
UNIX – also based off B language.

.
ANSI C
– common industrial language.

.
Java
– by James Gosling of Sun Microsystems
small, fast, reliable, transportable program
software for TV’s, VCR’s, telephones, etc.
Java applications – word processors, spreadsheets
Java applets – stored on remote computers, accessed through web.

.
HTML - HyperText Markup Language 
code for webpage.
use tags:
<TITLE> ... </TITLE>
<P> - paragraph
<H2>Second level heading</h2>
<ADDRESS> text ... </ADDRESS> - sigs, italic and/or right justified or indented

To see the HTML code used to create the Web page - Click on "View" in the menu bar and then click "Page Source."








C&C++ are among the world's most popular programming languages.

If you want C++ on your home personal computer, you can download it for free:

http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-cpp-express/thank-you?key=A1D5554A-253A-43AB-AC28-F7A29337C839&lang=enFree install code:
6VPJ7-H3CXH-HBTPT-X4T74-3YVY7

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Hello world!

  • classic 1972 tutorial
  • check that the compiler setup is working correctly
  • teach new users simple syntax& program structure

Open C++


Start,
All Programs,
Microsoft Visual Studio,
Microsoft Visual C++ 2010 Express


File →New→Project



→Win32 Console Application
→ enter a name for your project "Hello World"
→ ok→ next



→ select "" and ""
→Finish


You should now have a page that look like this:




Click the green arrow at the top to run the precompiled header
Would you like to build it?  Yes

Did you get a lnk error message?


Google the error message – see how to fix it:








Click the green arrow again,


Is the error message gone now?


Copy the following code into C++:


// Hello World.cpp : this is the comment line where you can tell users what your program does.  This program will output "Hello World"
//


#include "StdAfx.h"
#include "iostream"
using namespace std;
int main ()
{
    cout <<"Hello World"<<endl;
    system("PAUSE");
    return 0;
}


***Note - C++ is picky, it is case sensitive, you have to be very careful to get everything typed in correctly.




Click the green arrow,
would you like to build it? → yes




The program should then execute, a new window will pop up and say "Hello world"


What is in your program?

#include "StdAfx.h"
#include "iostream"

include instructs the pre-processor to include another file (the file SrdAfx.h, and iostream or in out stream in this case)

C++ has a library of many codes like "iostream" you can use to save yourself time & hassle.
http://www.cplusplus.com/reference/iostream/

iostream - input and output program, lets you use "cin" and "cout" to allow a user to imput data into the program, and for the program to output data back to the user.
StdAfx.h namespace, reduces compile & processing time
- http://www.cplusplus.com/articles/1TUq5Di1/


int main () 
the first function, where the program actually begins.

 

{}
Surrounds the function
{ start
end}

    cout <<"Hello World"<<endl;
Outputs "Hello World" to the user

;  C++ syntax, ends the command

    system("PAUSE");

Pauses the screen

    return 0;
indicates that the main function has ended




Functions provides a way of grouping commands together under a logical heading which can be called from a single line within your main program (no point rewriting and rewriting hundreds of lines of code every time you want a specific function – so get thousands of lines of code into one line of command)


 Library file
– collection of resources used in your computer program, allows sharing and importing of resources across one or more computers, to use and reuse as often as you wish.  You can write your own, or use existing files created by C++. – use library files instead of having to code everything yourself, just “include” them into your program. 

Open source – software whose source code is available free of charge to the public to use, copy, modify, etc.

Preprocessor commands
, command after # symbol, like #include – another separate program invoked by the compiler which includes extra source code definitions.  Include allows you to load separate source codes into your system. 

Editor – what you type your code in (like a notepad)

compiler – root of any programming language, transforms source code into assembly language or machine code, without it all you have is a block of text that doesn’t do anything.



Object – entity which can be manipulated – variables, functions, data structures, & classes

stream – input output channel linked to the console

overload – if an operator has more than one meaning, example: << inserts data into the cout stream instead of being a left shift.

 Commenting
// HW.cpp : Defines the entry point for the console application.

//


leave notes for other programmers who are looking at your code – text that is not part of the code itself, just explains what code does.



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

Assignment #1
This age calculator compiles, but does not calculate the correct age.

1. Study the program to see what it does.

2. change it so that it works using "if" statements:

if(abc)then(do xyz)

// Age Calc.cpp : Program to calculate someone's exact age.

//



#include "stdafx.h"

#include<iostream>

#include<conio.h>

using namespace std;

int main(int argc, _TCHAR* argv[])
{
       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;
      
       cout<<"\nEnter The Current Month(Eg:7):";
       cin>>currentmonth;

       cout<<"\nEnter The Current Year(Eg:2010):";
       cin>>currentyear;

       agey=currentyear-birthyear;
       agem=12-birthmonth;

       cout<<"\n\n\t\tYour Age is "<<agey<<" Years And "<<agem<<" Months ";

       getch();
       return 0;

}
 


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

Test your program:

Jack - born Jan 2005
(Already had his birthday this year - 9 years, and 2 months

Jill - born Sept 2006, (She has not had her birthday yet, 7 years, 6 months)


Hint:


//if(birthmonth > currentmonth) you have not had your birthday yet
       if(birthmonth > currentmonth)

       agey= ????
etc.




Assignment #2 




Write a program that calculate the coefficient of friction & forces acting upon an object at rest on an inclined plane.

Input: m, theta
Output: u, Fn, Ff


#include <math.h>

 // lets you use cos() sin() etc.//

#define GRAV 9.8

#define PI 3.141592654
Assignment #3 - your choice, such as:




Write a program that calculate the voltage drops and current in a simple series circuit.

Input: V, R1, R2, R3
Output: i, V1, V2, V3



or 
- write a program for your group project
- write an ENGR1201 grade calculator
     *clac what grade you need on the final to get an A in class considering what you have so far
- write a calorie counter
     * output how many miles you need to run in order to use up the food you just ate
- write any program you want that:
   *asks for user imput

   * performs a calculation based on that input
   * outputs something based on the calculation
~~~
// Age Calc.cpp : Program to calculate someone's exact age.

//

#include "stdafx.h"
#include <iostream>
#include <conio.h>
#include <time.h>

using namespace std;

int main(int argc, _TCHAR* argv[])
{
       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;
     
//automatically gets current month and year
    time_t t = time(0);   // get time now
    struct tm * now = localtime( & t );

       currentmonth = (now->tm_mon + 1);
       currentyear = (now->tm_year + 1900);




       agey=currentyear-birthyear;
       agem=12-birthmonth;

       cout<<"\n\n\t\tYour Age is "<<agey<<" Years And "<<agem<<" Months ";

       _getch();
       return 0;

}

No comments:

Post a Comment