Download presentation
Presentation is loading. Please wait.
Published byMervin Green Modified over 9 years ago
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
Review Algorithms Languages Implementation: Visual Studio.NET
3
Software development process Understand exactly what you are trying to do (problem domain) Figure out how you are going to do it (algorithm) 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
Evolution of running programs 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
9
Software development process Understand exactly what you are trying to do (problem domain) Figure out how you are going to do it (algorithm) 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?) Program the solution. To do this: 1. We need an answer to #2 above 2. We need to know how to use.NET Write up an algorithm that explains precisely how to do this task
12
Write an algorithm to do the microwave problem
13
Microwave Algorithm 1. Read in minutes, store in MIN 2. Read in seconds, store in SEC 3. In a variable TIME, store the value ( MIN x 60 ) + SEC 4. 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 > min; cout > sec; int time; time = min * 60 + sec; cout << “Total time is “ << time << endl; return 0; }
17
First Program - Outputs int main ( ) { int min, sec; cout > min; cout > sec; int time; time = min * 60 + sec; cout << "total time is " <<time << endl; return 0; } Output statements
18
First Program - Inputs int main ( ) { int min, sec; cout > min; cout > sec; int time; time = min * 60 + sec; cout << "total time is " <<time << endl; return 0; } Input statements
19
First Program - Variables #include using namespace std; int main ( ) { int min, sec; cout > min; cout > sec; int time; time = min * 60 + sec; cout << "total time is " <<time << endl; return 0; } Variable declarations from our first program.
20
Different types of containers hold different things Integers (int) Real numbers (double) Characters (char) Strings (later) Variables 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
21
Basic C++ Program Structure Header: Loads basic libraries Standard conventions Functions: Code/Instructions Must include “main” may include others #include using namespace std; int main ( ) { // statements return 0; }
22
Put it all together… #include using namespace std; int main ( ) { int min, sec; cout > min; cout > sec; int time; time = min * 60 + sec; cout << "total time is " <<time << endl; return 0; } Header info
23
Microsoft Visual Studio.NET 2005 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
24
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
25
Class Notes and Materials Log onto the computer Userid = Big Al, CWID = 12345678 userid = 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 vrbsky@cs.ua.edu 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.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.