Lab 9 Exercises.

Slides:



Advertisements
Similar presentations
Modular Programming With Functions
Advertisements

BBS514 Structured Programming (Yapısal Programlama)1 Functions and Structured Programming.
Lecture 2 Introduction to C Programming
Introduction to C Programming
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Introduction to C Programming
1 ICS103 Programming in C Lecture 3: Introduction to C (2)
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 14 – Student Grades Application: Introducing.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
1 Lab Assignment#5 Due 12/7 A car can hold 12 gallons of gasoline and it can travel 360 miles without refuelling. Write a program the displays the trip.
Introduction to C Programming
11 Chapter 5 METHODS. 22 INTRODUCTION TO METHODS A method is a named block of statements that performs a specific task. Other languages use the terms.
Functions A function is a snippet of code that performs a specific task or tasks. You use a multitude of functions daily when you do such things as store.
11 Chapter 4 LOOPS AND FILES. 22 THE INCREMENT AND DECREMENT OPERATORS To increment a variable means to increase its value by one. To decrement a variable.
Functions Parameters & Variable Scope Chapter 6. 2 Overview  Using Function Arguments and Parameters  Differences between Value Parameters and Reference.
Modular Programming Chapter Value and Reference Parameters t Function declaration: void computesumave(float num1, float num2, float& sum, float&
Looping While-continue.
Modular Programming Chapter Value and Reference Parameters computeSumAve (x, y, sum, mean) ACTUALFORMAL xnum1(input) ynum2(input) sumsum(output)
Mastering Char to ASCII AND DOING MORE RELATED STRING MANIPULATION Why VB.Net ?  The Language resembles Pseudocode - good for teaching and learning fundamentals.
Agenda  Perform Quiz#2 (20 Minutes)  Functions / Continued … –Functions - Definition –Types of Functions: Functions that do not accept or return a value.
Agenda  Commenting  Inputting Data from Keyboard (scanf)  Arithmetic Operators  ( ) * / + - %  Order of Operations  Mixing Different Numeric Data.
CP104 Introduction to Programming Selection Structures_3 Lecture 11 __ 1 The Switch Statement The switch statement provides another means to select one.
CNG 140 C Programming Lecture Notes 2 Processing and Interactive Input Spring 2007.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Value and Reference Parameters. CSCE 1062 Outline  Summary of value parameters  Summary of reference parameters  Argument/Parameter list correspondence.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
Writing JavaScript Functions. Goals By the end of this unit, you should understand … How to breakdown applications into individual, re-usable modules.
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)
CSC Programming I Lecture 6 September 4, 2002.
1 Program Planning and Design Important stages before actual program is written.
Starting Out with C++ Early Objects ~~ 7 th Edition by Tony Gaddis, Judy Walters, Godfrey Muganda Modified for CMPS 1044 Midwestern State University 6-1.
1 Brief Version of Starting Out with C++, 4th Brief Edition Chapter 6 Functions.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Agenda Perform Quiz #1 (20 minutes) Loops –Introduction / Purpose –while loops Structure / Examples involving a while loop –do/while loops Structure /
Chapter 3 : Top Down Design with Functions By Suraya Alias.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
CISC105 – General Computer Science Class 2 – 6/7/2006.
Lecture 7: Menus and getting input. switch Multiple-selection Statement switch Useful when a variable or expression is tested for all the values it can.
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
 2002 Prentice Hall. All rights reserved. 1 Chapter 5 – Control Structures: Part 2 Outline 5.1Introduction 5.2 Essentials of Counter-Controlled Repetition.
Copyright 2006 Addison-Wesley Brief Version of Starting Out with C++ Chapter 5 Looping.
Murach’s Visual Basic 2008, C7, modified or added© 2008, Mike Murach & Associates, Inc. Slide 1.
An Introduction to Programming with C++ Sixth Edition Chapter 5 The Selection Structure.
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
L131 Assignment Operators Topics Increment and Decrement Operators Assignment Operators Debugging Tips rand( ) math library functions Reading Sections.
Repetition statements
Introduction to Computer Programming
Chapter 2 Introduction to C++ Programming
ECE Application Programming
Chapter 2 - Introduction to C Programming
The Selection Structure
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
INPUT & OUTPUT scanf & printf.
Chapter 2 - Introduction to C Programming
1) C program development 2) Selection structure
Assignment Operators Topics Increment and Decrement Operators
Chapter 2 - Introduction to C Programming
Assignment Operators Topics Increment and Decrement Operators
Chapter 2 - Introduction to C Programming
JavaScript: Introduction to Scripting
CSC 1051 – Data Structures and Algorithms I
More Loops Topics Relational Operators Logical Operators for Loops.
Assignment Operators Topics Increment and Decrement Operators
Module 4 Loops and Repetition 9/19/2019 CSE 1321 Module 4.
Presentation transcript:

Lab 9 Exercises

Exercise 1 Write a function called letter_grade() that has type int and input parameter points and returns through an output parameter gradep the appropriate letter grade using a straight scale (90-100) is an A, 80-89 is a B, and so on. Return through a second output parameter just_missedp an indication of whether the student just missed the next higher grade (true for 89, 79, and so on). Traditionally, geography has been seen as affection our natural environment (physical geography) and our human environment (human geography). However, more recently, geography has been viewed as an emerging hi-tech discipline, with such systems as Earth Observation, GPS and GIS. We will examine each of these more closely.

Exercise 2 Write a program to model a simple calculator. Each data line should consist of the next operation to be performed from the list of below and the right operand. Assume the left operand is the accumulator value (initial value of 0). You need a function scan_data with two output parameters that return the operator and the right operand scanned from a data line. You need a function do_next_op that performs the required operation. Do_next_op has two input parameters (the operator and the operand) and one input/output parameter (the accumulator). The valid operations are: + add - subtract * multiply / divide ** power (raise left operand to power of right operand) q quit

Your program should also use a function print_error_message() To output error messages if the operation read from the user is not valid. Your calculator should display the accumulator value after each operation. A sample output follows. + 5.0 result so far is 5.0 ** 2 result so far is 25.0 / 2.0 result so far is 12.5 q 0 the final result is 12.5

Exercise 3 We want to write a program that allows the user enter a time value indicating hours, minutes and seconds in this format H M S and convert them to seconds. A sample execution would be: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * This program converts a time of day into seconds * Enter a valid Day time in this format: hours minutes seconds * To exit enter 0 0 0 40 5 --------- 13205 seconds 10 0 ---------- 15000 seconds 70 0 ---------- error 0 0 0---------- Bye bye !!!

Functions with no arguments Write a function called print_heading () that prints the heading that should be printed at the beginning (see above). Functions with input arguments and a return value Write a function in_seconds that takes three arguments hours, minutes, and seconds and that returns the corresponding value in seconds. A prototype of this function would be: int in_seconds(int hours, int minutes, int seconds). Function with input and output parameters (Call by reference vs Call by value) Modify the function in_seconds so that it checks for errors. If one of the input values is invalid it should return a 0, otherwise it should return a 1. The corresponding values in seconds should be returned in an output argument. The prototype for the modified version could be: int in_seconds(int hours, int minutes, int seconds, int *total)

STYLE Before the definition of each function you should have comments that describe what the function does. Look at the sample comment below for the function in_seconds() /***************************************************** * Function Name : in_seconds * Function Arguments : *seconds of type int (number of seconds) *minutes of type int (number of minutes) *hours of type int (number of hours) * *total of type int*(the total in seconds) * Return Value : 0 or 1 * Purpose : Converts the time into seconds *****************************************************/