1 Lab Session-8 CSIT-121 Fall 2003 w Call by Reference w Lab Exercise 1 w Lab Exercise for Demo w Practice Problems.

Slides:



Advertisements
Similar presentations
Pass by Value. COMP104 Pass by Value / Slide 2 Passing Parameters by Value * A function returns a single result (assuming the function is not a void function)
Advertisements

CS1010 Programming Methodology
Programming Functions: Passing Parameters by Reference.
1 11/3/08CS150 Introduction to Computer Science 1 Reading from and Writing to Files Section 3.12 & 13.1 & 13.5.
Overview creating your own functions calling your own functions.
1 Session-23 CSIT 121 Spring 2006 Revision Ch 7: Reference Parameters Revision Ch 7: Reference Parameters Chapter 8: Value Returning Functions Chapter.
1 Lab Session-6 CSIT221 Fall 2002 A Note About Destructors Using Pointers Implementing Stacks.
1 Lab Session-3 CSIT221 Spring 2003 b Group Worksheet 3 Exercise (Demo Required) b No new lab demo will be assigned to allow you to focus on HW#1.
1 Lab Session-4 CSIT121 Fall 2004 Scope of Variables Top Down Design Problem The Solution Lab Exercise for Demo.
1 10/29/07CS150 Introduction to Computer Science 1 Reading from and Writing to Files Section 3.12 & 13.1 & 13.5.
Chapter 8. 2 Objectives You should be able to describe: One-Dimensional Arrays Array Initialization Arrays as Arguments Two-Dimensional Arrays Common.
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
1 Lab Session-7 CSIT-121 Fall Revising Structured Choice 4 The While Loop variations 4 Lab Exercises.
1 Lab Session-6 CSIT-121 Spring 2005 Structured Choice The do~While Loop Lab Exercises.
1 Lab Session-3 CSIT 121 Fall 2004 Section-3 should finish Lab-1 Exercise first Division rules Operator precedence rules Lab Exercise.
1 Lab Session-9 CSIT-121 Fall 2003 w Random Number Generation w Designing a Game.
1 Lab Session-VIII CSIT-121 Fall 2000 w Formatted Output w Call by Reference w Lab Exercises w File Handling w Lab Exercises.
1 Lab Session-11 CSIT 121 Fall 2003 Using arrays in functions Programming Exercise.
CSCI/CMPE 4341 Topic: Programming in Python Chapter 3: Control Structures (Part 1) – Exercises 1 Xiang Lian The University of Texas – Pan American Edinburg,
1 10/25/06CS150 Introduction to Computer Science 1 Reading from and Writing to Files.
1 Lab Session-III CSIT-120 Spring 2001 Revising Previous session Data input and output While loop Exercise Limits and Bounds GOTO SLIDE 13 Lab session.
1 Lab Session-7 CSIT-121 Fall Introducing Structured Choice 4 The do~While Loop 4 Lab Exercises.
1 Session-9 CSIT 121 Spring 2006 Lab Demo (first 20 minutes) The correct way to do the previous lab sheet Function calls Calling void functions Calling.
1 Lab Session-VIII CSIT-121 Spring 2002 w Formatted Output w Call by Reference w Lab Exercises w File Handling w Lab Exercises.
1 Lab Session-3 CSIT221 Fall 2002 b Exception Handling b Lab Exercise (Demo Required)
1 Project 5: Median. 2 The median of a collection of numbers is the member for which there are an equal number less than or equal and greater than or.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
CS Class 07 Topics –  When software goes wrong  Count controlled loops  Sentential controlled loops  putting it all together Announcements.
1 Lab Session-III CSIT-120 Fall 2000 Revising Previous session Data input and output While loop Exercise Limits and Bounds Session III-B (starts on slide.
Modular Programming Chapter Value and Reference Parameters computeSumAve (x, y, sum, mean) ACTUALFORMAL xnum1(input) ynum2(input) sumsum(output)
CNG 140 C Programming (Lecture set 9) Spring Chapter 9 Character Strings.
Mastering Char to ASCII AND DOING MORE RELATED STRING MANIPULATION Why VB.Net ?  The Language resembles Pseudocode - good for teaching and learning fundamentals.
1 Lab Session-8 CSIT-121 Spring 2005 Call by Reference Lab Exercise for Demo Practice Problems.
Computer Programming 2 Lab(1) I.Fatimah Alzahrani.
Week 1 Algorithmization and Programming Languages.
1 INTRODUCTION TO PROBLEM SOLVING AND PROGRAMMING.
Value and Reference Parameters. CSCE 1062 Outline  Summary of value parameters  Summary of reference parameters  Argument/Parameter list correspondence.
Fundamental Programming: Fundamental Programming Introduction to C++
Writing JavaScript Functions. Goals By the end of this unit, you should understand … How to breakdown applications into individual, re-usable modules.
C ++ Basics by Bindra Shrestha sce.uhcl.edu/shresthab CSCI 3333 Data Structures.
Chapter 12: String Manipulation Introduction to Programming with C++ Fourth Edition.
CS161 Topic #16 1 Today in CS161 Lecture #16 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for)
Chapter 13 – C++ String Class. String objects u Do not need to specify size of string object –C++ keeps track of size of text –C++ expands memory region.
Control Structures (B) Topics to cover here: Sequencing in C++ language.
Basics of Most C++ Programs // Programmer: Clayton Price date: 9/4/ // File: fahr2celc.cpp 03. // Purpose:
A first program 1. #include 2. using namespace std; 3. int main() { 4. cout
A First Book of C++: From Here To There, Third Edition2 Objectives You should be able to describe: One-Dimensional Arrays Array Initialization Arrays.
Agenda Positional Parameters / Continued... Command Substitution Bourne Shell / Bash Shell / Korn Shell Mathematical Expressions Bourne Shell / Bash Shell.
Copyright © 2002 W. A. Tucker1 Chapter 9 Lecture Notes Bill Tucker Austin Community College COSC 1315.
An Introduction to Programming with C++ Sixth Edition Chapter 13 Strings.
Functions Structured Programming. Topics to be covered Introduction to Functions Defining a function Calling a function Arguments, local variables and.
Problem Solving and Program Design in C (5th Edition) by Jeri R. Hanly and Elliot B. Koffman CP 202 Chapter 6.
Higher Computing Science 2016 Prelim Revision. Topics to revise Computational Constructs parameter passing (value and reference, formal and actual) sub-programs/routines,
Fundamental Programming Fundamental Programming Introduction to Functions.
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
An Introduction to Programming with C++ Sixth Edition Chapter 5 The Selection Structure.
A Sample Program #include using namespace std; int main(void) { cout
Chapter Topics The Basics of a C++ Program Data Types
The Selection Structure
CMIS 102 Competitive Success-- snaptutorial.com
CMIS 102 Education for Service-- snaptutorial.com
CMIS 102 Teaching Effectively-- snaptutorial.com
Compound Assignment Operators in C++
Programming Funamental slides
Programming Funamental slides
Lecture 2 Fall 2011 September 13-15, 2011 Ghufran Ahmed
Fundamental Programming
Reading from and Writing to Files
Reading from and Writing to Files Part 2
Reading from and Writing to Files
Presentation transcript:

1 Lab Session-8 CSIT-121 Fall 2003 w Call by Reference w Lab Exercise 1 w Lab Exercise for Demo w Practice Problems

2 Call By Reference w Call by reference means passing the original variable to the function for changing w For example compute_sum_and_mean(int k, int j, int l, int& sum, float& mean) w It has three INPUT arguments and two REFERENCE arguments that are used to output the sum and mean

3 Lab Exercise 1 w Develop a program that calls a function to order two integer values in the increasing numerical order. w Function name order_values(int& num1, int&num2) w when passed values (x,y), it orders the same as (y,x) if it finds y to be less than x. w The function is void as it returns the values through reference arguments

4 Lab Exercise Demo Required Sec-01 Oct 28 Sec-02 Oct 30 w Develop a program that calls a function to read a text file and count the occurrences of all the vowels in the file. The program calls another function to display the results showing total number of characters in the file and number of times each vowel occurs. A sample program and a sample session are shown on the next slides.

5 Sample Program For Converting Letters to Uppercase w #include w using namespace std; w void main() w { w char letter; w letter='e'; w letter = toupper(letter); w cout<<letter<<endl; w }

6 Sample Session w Enter the file name: lab8doc.txt w Total Number of characters: 2654 w A: 108 w E: 251 w I: 118 w O: 129 w U: 74

7 Sample Text (Copy into lab8doc.txt file) CSCI Lab6: Functions - Pass by Reference, Arrays in C++ Goals: More practice with repetition and functions in C++ Obtain experience using pass by reference, arrays Preparation: After reading the problem description below, develop a simple solution algorithm for the problem. When you are ready to implement your algorithm, copy the lab directory to your account (enter the command cp -r ~csci160/Labs/Lab6. ). Change to Lab6 directory (enter the command cd Lab6) and use the commands discussed in Lab1 to implement and test your program. Problem Description: A store sells five different models of mobile phones. It keeps records of the number of units sold from each model by each sales person. At the end of the month, a summary of total sales needs to be prepared. Write a program to first read the unit price of each model and then allow the user to enter any number of (model, units) pairs. The different models are coded by the numbers 0, 1, 2, 3 and 4. End of input is indicated by giving a pair with 0 as the number of units. When implementing the program, follow the instructions given in lab6.C template. Examples: In the example below, the values entered by the user are indicated in italics. Example 1 $./lab6 Enter unit price of model 0: $79 Enter unit price of model 1: $89 Enter unit price of model 2: $99 Enter unit price of model 3: $109 Enter unit price of model 4: $129 Enter model and number of units (Eg. 2 10) To end input, with any model enter 0 for units (Eg. 1 0) Enter model and number of units: 1 5 Enter model and number of units: 2 4 Enter model and number of units: 3 1 Enter model and number of units: 4 1 Enter model and number of units: 0 12 Enter model and number of units: 2 6 Enter model and number of units: 5 3 Invalid model number. Last entry ignored... Enter model and number of units: 3 3 Enter model and number of units: 2 6 Enter model and number of units: 1 0 Summary of sales: Model Unit Price Units Total Total monthly sales = $ Assumptions/Restrictions: You may assume that the user will enter valid floating point values for the unit prices and integer values for model code and number of units. Test Set: To see which specific values are being used by the BATS routines, you may view the text files in the ~Lab6/tinp directory and the expected results in the ~Lab6/texp directory (using the Unix commands cat, more or less, e.g. cat tinp/test0).

8 Practice Exercises for Functions w Chapter 7 Programming Warm Up Exercise 12 w Chapter 7 Programming Problem 3