400 likes | 762 Views
Tutorial 1 – Car Payment Calculator and Guess the Number Application: Introducing Computers, the Internet and C++ Programming. Computer Hardware and Software 1.1 What Is a Computer? 1.2 Computer Organization 1.4 Computer Languages and Levels 1.9 Key Software Trend: Object Technology
E N D
Tutorial 1 – Car Payment Calculator and Guess the Number Application: Introducing Computers, the Internet and C++ Programming Computer Hardware and Software1.1 What Is a Computer? 1.2 Computer Organization 1.4 Computer Languages and Levels 1.9 Key Software Trend: Object Technology Computer Languages and IDEs 1.7 Early Procedural High-Level Languages 1.5 C and C++ 1.6 Java Python Integrated Development Environment (IDE) 1.8 Microsoft .NET FrameworkTutorial1.10 Compiling and Running C++ Applications 1.11 Test-Driving the Applications 1.12 Internet and Web Resources Lab and Homework Assignment
Objectives • In this tutorial, you will learn to: • Identify the characteristics of programming languages. • Apply the basics of object-oriented programming. • Run your first C++ application. • Locate additional C++ information using the Internet.
1.1 What Is a Computer? • Computers are designed to meet a specific set of requirements. • Computer History • In the early days, these requirements were to meet some military, science, civil, or commercial need. • For the military, it was predominately the calculation of ballistic tables. • For science to calculate the motion of the planets or the weather. • For civil keeping track of people and commercial keeping track of the money. • To meet these requirements the computer was conceived and described by its hardware and it instruction set. • Hardware components for all modern day computers, were codified by Von Neumann in his landmark paper describing the architecture of the EDVAC computer • the instruction set is a list of all the instructions the computer can understand – The Language of the Machine
1.2 Computer Organization • Five (not Six) basic components of a computer • Input • Obtains information from various input devices such as keyboard or mouse • Output • Places computer-processed information on output devices (making it available for use outside of the computer) • Memory • Usually volatile (data is lost after computer shuts off
1.2 Computer Organization (Cont.) • Arithmetic Logic Unit (ALU) • Performs arithmetic calculations and determines logic • Control • Oversees all computer activities • Memory Hierarchy (author’s sixth) • The Pyramid • Secondary Storage Unit • Nonvolatile(data is retained after computer shuts off) • Long term
1.2 Memory Hierarchy (author’s sixth) We are all familiar with the memory hierarchy (Figure 1) if not by name by experience. As we spiral out from the cpu memory becomes slower, larger, and more inexpensive. But where did the hierarchy come from and why does it exist at all. The earliest computer architects recognized the need for a hierarchical memory structure. Ideally one would desire an indefinitely large memory capacity such that any particular…word would be immediately available…We are …forced to recognize the possibility of constructing a hierarchy of memories, each of which has greater capacity that the preceding but which is less quickly accessible. • A.W. Burks, H.H. Goldstine, and J. von Neumann,Preliminary Discussion of the Logical Design of an Electronic Computing Instrument (1946).
1.2 Memory Hierarchy (Cont.) That the memory hierarchy works at all is a direct result of the Locality of Reference. As a general rule-of-thumb a program spends 90% of its execution time in only 10% of the code. An implication of locality is that based on the program’s recent past, one can predict with reasonable accuracy what instructions and data a program will use in the future. • Hennessy and Patterson 1st Edition This hypothesis leads directly to the Principle of Locality which has two dimensions: • Temporal locality (locality in time) — If an item is reference, it will tend to be referenced again soon. • Spatial locality (locality in space) — If an item is referenced, nearby items will tend to be referenced soon.
1.4 Computer Languages and Levels • Machine Languages − The language of the computer • Example: grossPay = basePay + overtimePay 9100 0100 9110 0102 0f01 9300 0101 • The numbers in the above example are in base 16 (hexadecimal) • Number Systems • Assembly Languages (ex. AVR, 80x86, ARM, MIPS, Itanium,…) • Machine language in a human readable form using mnemonics • Assemblers convert assembly languages to machine languages lds r16, basePay lds r17, overtimePay add r16, r17 sts grossPay, r16
1.4 Computer Languages and Levels (Cont.) • High-Level Languages (ex. Basic, Fortran, COBOL, Ada, Pascal) • Compilers convert to machine languages • Linkers package machine language files • Example: grossPay = basePay + overtimePay; • Interpretive Language (ex. Java, Flash, .NET) • Look and Function just like a High-Level Language. • Compilers convert to machine independent “intermediate” language • Interpreters run high-level/intermediate programs directly • Mid-Level Language (C and C++) • Combines the elements of high-level languages with the functionality of assembly language and has occasionally been referred to as a middle-level computer language.
1.9 Key Software Trend: Object Technology • Procedural Programming Languages (verb) • Focus on actions. Good analogy is a Cooking Recipes. • Objects (noun) • Object Circle • Properties – the attributes of an object (adjective). • Methods – what the object can do (adverb). May also be referred to as behaviors or functions. • Class • An object is an instance of a class definition. • Example: A basketball is an instance of a ball.
1.7 Early Procedural High-Level Languages • BASIC • Beginner’s All-Purpose Symbolic Instruction Code (BASIC) • For simple programs and teaching novices • Fortran (FORmula TRANslator) • Developed by IBM • Still used in engineering community • COBOL • Still used in business software • A very Verbose Language • Pascal • Designed for teaching structured programming (a precursor to Objects) • Ada • Sponsored by the Department of Defense • Named after Lady Ada Lovelace (the first computer programmer)
1.5 C and C++ • C is a middle-level computer language, combining the elements of high-level languages with the functionality of assembly language • C is portable, not tied to any particular hardware or operating system. • The C programming language was developed at Bell Labs circa 1969 – 1973 as a system implementation language for the nascent Unix operating system. • C was a direct descendant of the language B. The language B was developed by Ken Thompson in 1970 for the new UNIX OS. • B was a descendant of the language BCPL designed by Martin Richards, a Cambridge University student visiting MIT. Sources: • http://www.hitmill.com/programming/cpp/cppHistory.html • http://cm.bell-labs.com/cm/cs/who/dmr/chist.html
1.5 C and C++ • C++ was written by Bjarne Stroustrup at Bell Labs during 1983-1985. • C++ is an extension of C. Prior to 1983, Bjarne Stroustrup added features to C and formed what he called "C with Classes". He had combined the Simula's use of classes and object-oriented features with the power and efficiency of C. • The term C++ was first used in 1983. • Hybrid language • C style • Provides capabilities for Object-Oriented Programs (OOPs)
1.5 C and C++ (Cont.) • C++ is a vast language that has evolved over many years. • C++ is a mainstream language used in industry, engineering, and education. • C++ is a lean language in that you add to it libraries that your particular program(s) require and exclude overhead libraries that are not needed. • The hope is to create reusable code and minimize redundancy...this is the notion of OOP or Object Orientated Programming.
1.6 Java • Java and Python are general-purpose interpreted, object-oriented, high-level programming languages • Java was developed by James Gosling at Sun Microsystems and released in 1995. • The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities. • Java applications are typically compiled to bytecode (class file) that can run on any Java Virtual Machine (JVM) regardless of computer architecture. • It is intended to let application developers "write once, run anywhere". • Java is currently one of the most popular programming languages in use, and is widely used from application software to web applications. Source: http://en.wikipedia.org/wiki/Java_%28programming_language%29
Python • Like Java, Python is a general-purpose interpreted, object-oriented, high-level programming language. • Work on Python started in December 1989 by Guido van Rossum in the Netherlands as a successor to the ABC programming language • C provided some of Python's syntax, • One of the early objectives of Python was to be easily learnable and not too arcane in its syntax and semantics, reaching out to non-programmers − this is no longer an active concern. Source: http://en.wikipedia.org/wiki/History_of_Python
Integrated Development Environment (IDE)also known as integrated design environment or integrated debugging environment • An IDE is a software application that provides comprehensive facilities to computer programmers for software development. • An IDE normally consists of: • a source code editor • a compiler and/or an interpreter • build automation tools • a debugger • Typically an IDE is dedicated to a specific programming language, providing a feature set for the programming paradigms of the language. • Some multiple-language IDEs are in use, such as Eclipse, NetBeans, and Microsoft Visual Studio to name a few.
1.8 Microsoft .NET Framework • The Microsoft .NET Framework is a software framework for MicrosoftWindowsoperating systems. • The .NET Framework supports several programming languages (Visual Basic, C++, C#) which allows language interoperability (each language can use code written in other languages). • All .NET programs are by definition high-level running on an application virtual machine, so that programmers need not consider the capabilities of the specific CPU (Platform independent). • The .NET Framework includes a large library • The library provides user interface, data access, database connectivity, cryptography, web application development, numeric algorithms, and network communications. • The class library is used by programmers, who combine it with their own code to produce applications. • The .NET library is available to all the programming languages that .NET supports.
1.10 Compiling and Running C++ Applications • Files • Source code files (.cpp) • Header files (.h) • Executable files (.exe) • Compilation • Turns high-level source code into machine language code • Command prompt • Allows text instructions to be given to the computer
How To Open Dos Prompt Command in Windows 7 • What is it? • It’s a right-click context menu that opens a command prompt window at the current working directory, wherever you pop up the context menu. • How? • In Windows Explorer, simply hold the Shift key and right-click the folder you want to set as working directory, choose Open Command Window here. Source: http://www.windows7hacker.com/index.php/2009/08/how-to-open-dos-prompt-command-here-in-windows-7-and-more/
Beginning directory for Windows 2000 1.10 Compiling and Running C++ Applications (Cont.) Figure 1.1 Command Prompt window in Windows 2000.
Beginning directory for Windows XP 1.10 Compiling and Running C++ Applications (Cont.) Figure 1.2 Command Prompt window in Windows XP.
1.11 Test-Driving the Car Payment Calculator and Guess the Number Applications • Open Command Prompt • Start > All Programs > Accessories > Command Prompt • Change directories • Type cd C:\Examples\Tutorial01\CarPayment • Type cd C:\Examples\Tutorial01\GuessNumber • Run an application • Type CarPayment • Type GuessNumber
Note that the current directory changed 1.11 Test-Driving the Car Payment Calculator and Guess the Number Applications (Cont.) Figure 1.3 Changing to the Car Payment Calculator application’s directory.
Executing the CarPayment application 1.11 Test-Driving the Car Payment Calculator and Guess the Number Applications (Cont.) Figure 1.4 Running the Car Payment Calculator application.
1.11 Test-Driving the Car Payment Calculator and Guess the Number Applications (Cont.) Figure 1.5 Car Payment Calculator with data entered.
Close box Results displayed in tabular format 1.11 Test-Driving the Car Payment Calculator and Guess the Number Applications (Cont.) Figure 1.6 Car Payment Calculator application displaying calculation results.
Note that the current directory changed 1.11 Test-Driving the Car Payment Calculator and Guess the Number Applications (Cont.) Figure 1.7 Changing to the Guess the Number application’s directory.
Executing the GuessNumber application 1.11 Test-Driving the Car Payment Calculator and Guess the Number Applications (Cont.) Figure 1.8 Running the Guess the Number application.
1.11 Test-Driving the Car Payment Calculator and Guess the Number Applications (Cont.) Figure 1.9 Entering an initial guess.
Application displays whether your guess is too high or too low 1.11 Test-Driving the Car Payment Calculator and Guess the Number Applications (Cont.) Figure 1.10 Entering a second guess and receiving feedback.
Entering additional guesses Entering the correct guess 1.11 Test-Driving the Car Payment Calculator and Guess the Number Applications (Cont.) Figure 1.11 Guessing the correct number.
1.12 Internet and Web Resources • www.deitel.com • www.prenhall.com/deitel • www.softlord.com/comp • www.elsop.com/wrc/h_comput.htm • www.w3.org/History.html • www.netvalley.com/intval.html • www.ansi.org • www.cuj.com
Lab and Homework Assignment • Buy the Textbook. • Copy example from SimplyCpp CD to your local hard drive (See preface starting on page xxv). • Download and Install Visual Studio 2010 Express • Run the Car Payment Calculator and Guess the Number Applications. • Do Tutorial 1 − Car Payment Calculator and Guess the Number Application. • Answer and Turn-in Tutorial 1 Questions at the end of the Chapter. Always write the question followed by the answer. Remember to highlight the answer. • Search the Web for a Good “Hello World” Tutorial using the Microsoft Visual Studio IDE. Include as question 1.16. For the answer write the URL and in a few sentences why you like the tutorial. Web Tutorial may be a website or a video. • Due next Wednesday