Upload
mervin-green
View
223
Download
2
Embed Size (px)
Citation preview
CS 114 – Class 02 Topics
Computer programsUsing the compiler
AssignmentsRead pages 21-38 for Thursday.We will go to the lab on Thursday
Review
Algorithms Languages
Implementation: Visual Studio .NET
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)
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
languageHigh-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 classSometimes does things unexpectedly
Later in the semesterWe will use linux – Unix like operating systems
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
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)
Today’s problem Microwave oven components
Control UnitHigh Voltage Unit
Control section accepts cook time from user Input is two numbers [minutes and seconds]
High Voltage Unit needs time in secondsNeed 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?)
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
Write an algorithm to do the microwave problem
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
Almost ready to code a solution
Understand the problem Know an algorithm to solve it Next steps
Basic structure & format for a C++ programBasics 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;
}
First Program - Outputsint 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;
}
Output statements
First Program - Inputsint 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;
}
Input statements
First Program - Variables#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;
}
Variable declarations fromour first program.
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
Basic C++ Program Structure
Header:Loads basic librariesStandard conventions
Functions:Code/InstructionsMust include “main”may include others
#include <iostream>
using namespace std;
int main ( ) {
// statements return 0;
}
Put it all together…#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;
}
Header info
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: [email protected]
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
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
[email protected] Tues. 9/2 before classRun the program using the instructions at the link
belowPrint 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.