1 / 27

CS 114 – Class 02

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.

cgomez
Télécharger la présentation

CS 114 – Class 02

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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

  2. Languages Algorithms Implementation: Visual Studio .NET Review

  3. 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)

  4. 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

  5. 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

  6. 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

  7. 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

  8. 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

  9. 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)

  10. 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)

  11. 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

  12. Write an algorithm to do the microwave problem

  13. 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

  14. 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

  15. 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

  16. 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; }

  17. 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

  18. 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

  19. #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.

  20. 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

  21. 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;

  22. #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

  23. 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

  24. 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

  25. 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!!

  26. 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

  27. End of Class 02 Assignments: Read pages 21-38 Get an Engineering computer account if you don’t have one.

More Related