270 likes | 286 Vues
CS 114 – Class 02. Topics Computer programs Using the compiler Assignments Read pages 21-38 for Thursday. We will go to the lab on Thursday. Languages. Algorithms. Implementation: Visual Studio .NET. Review. Software development process.
E N D
CS 114 – Class 02 • Topics • Computer programs • Using the compiler • Assignments • Read pages 21-38 for Thursday. • We will go to the lab on Thursday
Languages Algorithms Implementation: Visual Studio .NET Review
Software development process Figure out how you are going to do it(algorithm) Understand exactly what you are trying to do(problem domain) Code your solution(programming)
What is a computer program? • Once you have figured out how to solve the problem and have an algorithm • Type in code (words) specific to a computer language • High-level languages: C++, C, Java, etc. • Lower-level languages: Assembly language • Must follow format, etc. for language
How to run program • Must execute the program on a computer • Language you use is converted (compiled) to machine code the computer can understand (bits – 1’s, 0’s) • This machine code is then run (executed) on the computer • Results produced from program (output) • Print list of phone numbers • Play video or music • Create a new file on computer and put list of classes in file • Move robot around room
How to run a program • We will use the high-level language C++ • To execute the program we will use .NET, • Microsoft product that runs under windows (operating system) • .NET is an interactive environment • In one step: .NET will compile your program to machine code the computer can understand - then link/load and execute the program for you • Can test/debug in .NET
Visual Studio .NET • Pro - Don’t have to worry about details, .NET does it for you • Cons -.NET has many features • too many for us to use in this class • Sometimes does things unexpectedly • Later in the semester • We will use linux – Unix like operating systems
Old days – used punch cards and mainframe Punch cards for your program Submit & wait several hours Repeat until correct Today Interactive environment Permits immediate: Program development Compile and execute Test and debug Lots of environments We use: Microsoft Visual Studio .NET 2005 Don’t use the system until you know how to solve the problem Must know the algorithm Evolution of running programs
Software development process Figure out how you are going to do it(algorithm) Understand exactly what you are trying to do(problem domain) Code your solution(programming)
Today’s problem • Microwave oven components • Control Unit • High Voltage Unit • Control section accepts cook time from user • Input is two numbers [minutes and seconds] • High Voltage Unit needs time in seconds • Need to convert two numbers representing minutes (MM) and seconds (SS) to a total number of seconds to cook (TIME) • Our program: reads two numbers (MM & SS), prints one (TIME)
Microwave oven conversion Make sure everyone at your table understands the problem(What is the output with the input: 04 45?) Write up an algorithm that explains precisely how to do this task Program the solution. To do this:1. We need an answer to #2 above2. We need to know how to use .NET
Microwave Algorithm • Read in minutes, store in MIN • Read in seconds, store in SEC • In a variable TIME, store the value( MIN x 60 ) + SEC • Print out the result
Almost ready to code a solution • Understand the problem • Know an algorithm to solve it • Next steps • Basic structure & format for a C++ program • Basics of .NET (how to build a simple program) • Still need to know how to use C++ and .NET
Our algorithm in pseudo-code • Begin program • Print out (display) “enter minutes:” • Read in (input) minutes from user • Where to put minutes? • Print out (display) “enter seconds:” • Read in (input) seconds from user • Compute cook time • Printout “total time” and cook time • End program
Implementing our algorithm in C++ • Comments: • All statements end with a semi-colon • cin and cout are used for input and output • One assignment statement computes our answer • Statement can span multiple lines • Use three variables to store values (integers) int main ( ) { int min, sec; cout << “Enter minutes : “; cin >> min; cout << “Enter seconds : “; cin >> sec; int time; time = min * 60 + sec; cout << “Total time is “ << time << endl; return 0; }
int main ( ) { int min, sec;cout<<"enter minutes:";cin >> min;cout<<"enter seconds:";cin >> sec;int time;time = min * 60 + sec;cout << "total time is " <<time << endl;return 0; } First Program - Outputs Output statements
int main ( ) { int min, sec;cout<<"enter minutes:";cin >> min;cout<<"enter seconds:";cin >> sec;int time;time = min * 60 + sec;cout << "total time is " <<time << endl;return 0; } First Program - Inputs Input statements
#include <iostream> using namespace std; int main ( ) { int min, sec;cout << "enter minutes: ";cin >> min;cout << "enter seconds: ";cin >> sec;int time;time = min * 60 + sec;cout << "total time is " <<time << endl;return 0; } First Program - Variables Variable declarations from our first program.
Different types of containers hold different things Integers(int) Real numbers(double) Characters(char) Strings(later) A Variable is a container Holds something needed in your algorithm Variable names correspond to a specific location in memory. There are Naming Conventions for variables For example, you can’t name a variable 5 Variables
Basic C++ Program Structure int main ( ) { // statements return 0; } Functions: Code/Instructions Must include “main” may include others Header: Loads basic libraries Standard conventions #include <iostream> using namespace std;
#include <iostream> using namespace std; int main ( ) { int min, sec;cout << "enter minutes: ";cin >> min;cout << "enter seconds: ";cin >> sec;int time;time = min * 60 + sec;cout << "total time is " <<time << endl;return 0; } Put it all together… Header info
University All CoE labs Your own personal machines: Legal copy is free at support.cs.ua.edu/ Click on Go to UA MSDNAA Site Username: student@cs.ua.edu PW: csPass06 Must give UA email address Microsoft Visual Studio .NET 2005
Visual Studio .NET Designed for large, commercial applications 114 uses a small portion of its capabilities Future classes use more features Visual Studio C++ Express is smaller & free www.microsoft.com/ express/vc Microsoft Visual Studio .NET 2005
Class Notes and Materials • Log onto the computer • Userid = <first initial> <last initial> <last 4 digits CWID> • Big Al, CWID = 12345678userid = ba5678 • Password = userid • Domain = COE • Change your password • Check your Bama mail!!
Homework • Homework #1 Due: Thurs. 8/28 before class • Send me e-mail so I will have everyone’s e-mail account in case of announcements • You don’t have to use your bama account • Homework #2 Due: e-mail your .cpp file to vrbsky@cs.ua.edu Tues. 9/2 before class • Run the program using the instructions at the link below • Print an additional line after hello that says goodbye http://cs.ua.edu/~vrbsky/CS114/Instr.NET.htm
End of Class 02 Assignments: Read pages 21-38 Get an Engineering computer account if you don’t have one.