CS 202 Computer Science II Lab Fall 2009 September 10.

Slides:



Advertisements
Similar presentations
Lecture Computer Science I - Martin Hardwick The Programming Process rUse an editor to create a program file (source file). l contains the text of.
Advertisements

Lecture Computer Science I - Martin Hardwick Strings #include using namespace std; int main () { string word; cout
Computer Science 1620 Math Library. Remember this program? suppose that I invest $25000 into a mutual fund that returns 8% per year. Write a program to.
CPSC 441 TUTORIAL – JANUARY 16, 2012 TA: MARYAM ELAHI INTRODUCTION TO C.
Introduction to C++ Programming. Brief Facts About C++ Evolved from C Designed and implemented by Bjarne Stroustrup at the Bell Labs in the early 1980s.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 102 Computer Programming II (Lab:
Templated Functions. Overloading vs Templating  Overloaded functions allow multiple functions with the same name.
1 11/3/08CS150 Introduction to Computer Science 1 Reading from and Writing to Files Section 3.12 & 13.1 & 13.5.
Writing and Testing Programs Drivers and Stubs Supplement to text.
Command-line arguments CS 201 Fundamental Structures of Computer Science.
CS 202 Computer Science II Lab Fall 2009 September 17.
1 10/29/07CS150 Introduction to Computer Science 1 Reading from and Writing to Files Section 3.12 & 13.1 & 13.5.
1 9/25/06CS150 Introduction to Computer Science 1 Nested Ifs, Logical Operators, exit() Page 194.
CS 202 Computer Science II Lab Fall 2009 September 3.
1 10/25/06CS150 Introduction to Computer Science 1 Reading from and Writing to Files.
Overview scope - determines when an identifier can be referenced in a program storage class - determines the period of time during which that identifier.
CS 202 Computer Science II Lab Fall 2009 October 22.
CS 240: Data Structures Supplemental: Command Line Input.
C++ Programming Language Day 1. What this course covers Day 1 – Structure of C++ program – Basic data types – Standard input, output streams – Selection.
1 The UNIX date command myclock.cpp example The C/C++ time() and ctime() functions myclock2.cpp example Inline function definitions Inline class member.
Binary Search Trees II Morse Code.
Variables, Functions & Parameter Passing CSci 588 Fall 2013 All material not from online sources copyright © Travis Desell, 2011.
Jan. 29, 2008(c) Mike Barnoske Introduction to Runtime Debugging Using the Visual C++ IDE COP 4331: OO Processes for SW Development © Dr. David A. Workman.
CS1201: Programming Language 2 Recursion By: Nouf Almunyif.
1 Lab 2 “Hello world” in Unix/Linux #include "std_lib_facilities_4.h" int main(){ cout
ITEC 320 C++ Examples.
File ▪ File – Unit of logical storage – Aid in manipulating exact sector of file data ▪ Abstract view of secondary physical storage devices ▪ Without files.
Multiple Files. Monolithic vs Modular  one file before  system includes  main driver function  prototypes  function.
CHAPTER 2 PART #1 C++ PROGRAM STRUCTURE 1 st semester H 1 King Saud University College of Applied studies and Community Service Csc 1101 By:
An Example of Windows Forms Applications Windows-based application –Win Forms Control structures (selection and repetition) Graphics Read integers from.
Previously Repetition Structures While, Do-While, For.
Chapter 8 Scope of variables Name reuse. Scope The region of program code where it is legal to reference (use) a variable The scope of a variable depends.
1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week 9.
Chapter 7 Pointers: Java does not have pointers. Used for dynamic memory allocation.
1 Command-Line Processing In many operating systems, command-line options are allowed to input parameters to the program SomeProgram Param1 Param2 Param3.
Chapter 2 part #1 C++ Program Structure
CS Class 03 Topics  Sequence statements Input Output Assignment  Expressions Read pages Read pages 40 – 49 for next time.
Fall 2002 CS 325 Class Notes Page 1 Lecture 25 Today –exec() in Unix –CreateProcess in Windows Announcements.
April 11, 2005 More about Functions. 1.Is the following a function call or a function header? calcTotal(); 2.Is the following a function call or a function.
Make Make is a system utility that automatically compiles your programs for you Make looks for a file named Makefile (or makefile) in the current directory.
CS431-cotter1 Linux Programming, Processes, and Threads Man pages (fork, clone, execve, pthread_create) The Linux Programming Interface – Kerrisk, No Starch,
Dayu Zhang 9/10/2014 Lab03. Outline Brief Review of the 4 Steps in Hello.cpp Example Understand endl and \n Understand Comment Programming Exercise -
C:\Temp\Templates 4 5 Use This Main Program 6.
C++ Namespaces, Exceptions CSci 588: Data Structures, Algorithms and Software Design All material not from online sources copyright © Travis Desell, 2011.
Functions Jordi Cortadella Department of Computer Science.
1 Structure of Simple C++ Program Chapter 1 09/09/13.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
MR. CRONE Generating Random Numbers. Random Numbers Many programs require the computer to generate random numbers Random numbers are used in many applications.
1 Using an XML Parser. 2 Objective You will be able to use a publically available open source parser to convert an XML file into an internal data structure.
Linux CSE 1222 CSE1222: Lecture 1BThe Ohio State University1.
Lecture 3: Getting Started & Input / Output (I/O)
MT262A Review.
Topic Pre-processor cout To output a message.
Intro to Programming Week # 6 Repetition Structure Lecture # 10
Chapter 2 part #1 C++ Program Structure
Compilation and Debugging
Compilation and Debugging
Command Line Arguments
Linux 104 Training Module File Editing.
CS 1430: Programming in C++ Turn in your Quiz1-2 No time to cover HiC.
Starting Out with C++: From Control Structures through Objects
Code::Block vs Visual C++
CS1201: Programming Language 2
Pointers and dynamic objects
COMS 261 Computer Science I
Separating Interface from Implementation
Reading from and Writing to Files Part 2
Introduction to Algorithms and Programming COMP151
How to Create your First Program
Chapter 2 part #1 C++ Program Structure
Presentation transcript:

CS 202 Computer Science II Lab Fall 2009 September 10

Today Topics Reusing programs (making header files) Script mounting your USB Copy-Paste in vi

Reusing Programs Why reuse? Copy-paste the code – Advantages: NONE – Disadvantage: a lot!! Using header files Object-oriented programming

Header file example… Create headerExample directory – *do not delete files Create basicMath.h file : 1./* basicMath.h */ 2. 3.int add (int a, int b); 4.int mul (int a, int b);

.Header file example.. Create basicMath.cpp file : 1./* basicMath.cpp */ 2.int add (int a, int b) { 3. return a+b; 4.} 5.int mul (int a, int b) { 6. return a*b; 7.}

..Header file example. Create main.cpp file : 1.#include 2.#include "basicMath.h" 3.using namespace std; 4.int main(int argc, char ** argv) { 5.int a, b; 6.cout << " Name: Your-Name " << endl; 7.cout << " Section: Your-Section-No " << endl; 8.if (argc > 2) { 9.a = atoi(argv[1]); 10.b = atoi(argv[2]); 11.} else { 12.a = 1; 13. b = 2; 14.} 15.cout << a << " + "<< b << " = " << add(a, b) << endl; 16.cout << a << " * "<< b << " = " << mul(a, b) << endl; 17.return 0; 18.}

…Header file example – g++ -c main.cpp – g++ -c basicMath.cpp – Or: – g++ -c *.cpp – g++ -o main main.o basicMath.o –./main 12 5 > output.out

Exercise After successfully running the program, add the following function to “basicMath.cpp”, and try to make it work by editing main.cpp & basicMath.h int min (int a, int b) { return (a < b) ? a : b; } Testing Program –./main –./main > output.out Print output.out – lpr output.out

Script Script [file name] … exit Default file name: typescript

mounting your USB df -Tto see list of mounted devices mount /dev/fd0 /mnt/floppy mount /dev/cdrom /mnt/cdrom mount /dev/sda1 /mnt/usbdisk

Copy-Paste in vi (n)yy (n) lines to buffer y(n)w yanks (n) words to buffer p puts yanked or deleted text after cursor P puts yanked or deleted text before cursor

Questions?