Lab 2: Performance Measurement Date: 12 June 2009 Number of Problems: 4

Size: px
Start display at page:

Download "Lab 2: Performance Measurement Date: 12 June 2009 Number of Problems: 4"

Transcription

1 Lab 2: Performance Measurement Date: 12 June 2009 Number of Problems: 4 Performance Measurement In the classroom, we learn how to measure and compare algorithm based on theoretical point of view using asymptotic notation. However, there are cases when you need to actually test your algorithm in real world and observe its behavior in practice. This lab concentrates on measuring performance of algorithm using experimental data. You will learn how to measure instruction count and real clock time that the algorithm uses. Moreover, you will learn how to interpret the empirical result and use it to improve theoretical analysis of the algorithm. In this lab, you will learn the following subject Writing output to file Measure real clock running time Measure instruction count Using GNUPlot to graphically analyze the data of the experiment Starting Code This lab involves several problem, each need several lines of code. Instead of having you going through the pain of writing everything again, a starting code for each problem is provided. You can download the starting code at a. Scoring Sheet At the end of this document, you will find the scoring sheet. This sheet lists the problem that you have to do plus some additional questions you need to answer. Try your best to answer the question. The grading of each problem is also done in this paper. Instructors and TAs will check your work and give his/her signature on this paper one your solution is correct. Remember that you can submit your solution as many times as you like. At the end of the lab, you must present this paper to TA.

2 Problem 0: Writing output to file Input: nothing Output: the file output.txt containing first 45 Fibonacci Numbers Objective The student can write an output to a file Introduction In the previous lab, we have learned how to display a text on a screen. For this lab, we are going to display the output to a text file. In C language, writing something to a text file can be done by the function int fprintf(file *stream, const char *format,...); which works similar to the printf we used in the previous lab. However, the function fprintf requires additional argument before the text to display. The required argument is a file pointer which is a variable that indicates the file to be written into. This problem asks you to write a program that display the first 46 Fibonacci numbers to a text file named output.txt. However, you need not to rewrite another Fibonacci number code. A starting code for this problem can be found in Folder named Lab2 Prob0. *** TASK1: Your task is to write a program that displays the first 45 Fibonacci numbers to the file output.txt *** File Pointer C interacts with file through a file pointer. A file pointer is declared as a type FILE*. It is link to the actual file on the disk by the function fopen which requires the file name and mode of operation of the file. Once a file pointer is created, it can be used to read and write data to the file in the same way as reading data from a keyboard or writing data to a screen. One additional requirement is that once the reading or writing is done, we need to release the file using the function fclose. The following code snippet shows how to write a text Hello, CP to a file. int main(int argc, char *argv[]) { FILE *fp; fp = fopen("output.txt","w"); fprintf(fp,"hello, CP!\n"); // declar a file pointer called fp // link fp to a file called "output.txt" // using "w" mode (writing mode) // write something to the file linked by fp } fclose(fp); return 0; // close the file, after this line, // fp cannot be used in fprintf

3 Starting Code The starting code can be found in folder Lab2 Prob0. The main file is main.c. It contains two functions: the main() function and the Fibo() function. The Fibo() function provide you the computation of Fibonacci number. You need not to modify it. You need to modify the main function such that the Fibonacci number is stored in the required text file.

4 Problem 1: GNUPlot and Hailstone Sequence Input: nothing Output: A file hailstone.txt containing the step used to compute the hailstone sequence of the starting value from 1 to 9999 Objective The student can measure number of operation used in a computation. The student can plot a graph using GNUPlot. The student can write simple while loop structure. Introduction There are several interesting sequences in Mathematics. Fibonacci number which was introduced in Lab 1 is one of them. For this lab, we will introduce another sequence known as Hailstone sequence. First, let us look at the following operation on an integer X. If X is even, divide it by 2 If X is odd, multiply it by 3 and add 1 Formally speaking, the operation is defined by this function /2 3 1 For example, if X is 5, this operation produces5 x The interesting thing is that if we repeat this operation over and over again, eventually, the number will become 1. For example, the previous example shows that 5 becomes 16, we then apply the operation on 16 which yield 8, we then apply it again yielding 4, then 2, then 1. The progress of this operation starting at X = 5 is the following sequence. 5, 16, 8, 4, 2, 1 Another example is when we start with X = 21, the resulting sequence is as follow. 21, 64, 32, 16, 8, 4, 2, 1 The sequence resulting from the operation is called a Hailstone sequence*. We define the length of the sequence as a number of operations performed to bring the starting value to 1. For example, the length of the Hailstone sequence of the starting number 5 is 5, the length of the Hailstone sequence of the starting number 21 is 7. Another interesting property of the sequence is that the length of sequence of each starting number is in irregular patter. For example, the length of the number 26 is 10 while the length of the number 27 is 111, taking the value up to around 9,000. In this problem, you are required to display the relation between the Hailstone starting number and the length of the sequence.

5 *** TASK2: This problem asks you to write a function to count the length of a Hailstone sequence of any positive integer. *** *** TASK3: This problem also asks you to draw a graph representing the relation between the starting number and the length of the associated Hailstone sequence. *** As in the Problem 0, you are not required to write everything. Your can open the project in the folder Lab2 Prob1 to find the starting code. In the code, you need to modify the Hailstone function to return the length of the given starting number. The given code computes the length of the starting number from 1 to 9,999 and save the starting number and the length into a file called Hailstone.txt. In the next section, you will learn how to use a tool called GNUPlot to display a graph using the data in Hailstone.txt. Starting Code The starting code can be found in folder Lab2 Prob1. You need to modify function int Hailstone(long x). The function should return the number of step that brings the starting number x to the number 1. The variable step in the function is declared to store the length of the sequence. No need is required for the other part. The main code already uses the function Hailstone() to record the number of step into the file Hailstone.txt. Using GNUPlot The result of this problem is a file named Hailstone.txt where each line contain a number X and L x where L x is the length of the Hailstone sequence starting at X. The first few lines of the file should be like this To have a better look at the meaning of this number, our next task is to draw a graph where the x axis is the starting number while the y axis is the length of the associated Hailstone sequence. This can be easily done by a tool called GNUPlot. 1. Download the GNUPlot for win32 from a and save it on Drive Z:\ 2. Extract the file gp425win32.zip on Z:\ which should give a folder called Z:\gnuplot

6 Figure 1: Extracting GNUPlot 3. Launch GNUPlot by opening the program Z:\gnuplot\bin\wgnuplot.exe Figure 2: Launching GNUPlot 4. The main interface of GNUPlot is shown as in Fig. 3. In most case, it will be unreadable. This could be fixed by changing the default font. This could be done by right click on the white area of the windows.

7 Figure 3: The main interface of GNUPlot 5. The font dialog should appear as in Fig. 4. Set the font to be Courier New and the size to be 10 and then click OK. Now, GNUPlot is ready to be used. Figure 4: Font Selection. 6. The next step is to tell GNUPlot that we would like to plot something from a file in our folder. Click on ChDir button to change the directory to this problem. That should be Z:\AlgoLab\Lab2 Prob1

8 Figure 5: Change the directory to our problem. 7. Tell GNUPlot to plot the data in file Hailstone.txt by typing plot hailstone.txt in the main interface of GNUPlot and press enter. Figure 6: Plot the file. 8. GNUPlot should produce a graph similar to Fig. 7. Call your TA to check up your answer.

9 Figure 7: Graph showing relation between the starting number and the length of the associated Hailstone sequence. Supplementary Explanation Collatz Conjecture Lothar Collatz, a German mathematician, conjectured in 1937 that, any positive integer can be used as a starting number in a Hailstone sequence, i.e., any positive number would eventually leads to 1 by the operation. However, no prove is found for his conjecture. It has been shown by computer program that positive integers from 1 up to around 5 trillion produce Hailstone sequence. No counter example is found until now. GNUPlot GNUPlot is a graphical data plotter. It can plot 2D and 3D graph as well as surface and function. You could try several commands in GNUPlot to experiment with it. For example, let us try the following commands: plot sin(x) plot sin(x) linewidth 2, cos(x) linewidth 2 plot 10 * x, x**2 splot sin(y) * cos(x) The official homepage of GNUPlot is at

10 Problem 2: Fibonacci by recursive and wall clock time Input: nothing Output: A file fibo.txt containing the time used to compute each Fibonacci Numbers using recursive method from 1 st to 40 th Fibonacci number. Objective The student can measure time used by an algorithm The student can empirically compare running time of several algorithms Introduction The Fibonacci sequences introduced in the previous lab can be computed by several approaches. The code given in the first lab and in the first problem of this lab using an approach called Dynamic Programming which will be covered later in the course. This method is very fast comparing to other approaches. In this problem, we will introduce another approach for Fibonacci Numbers. The Fibonacci number is defined recursively, thus, it is natural to compute the Fibonacci number using recursive method. This method, while it follows naturally from the definition of the sequence, is not a good approach. It takes much longer time than the Dynamic Programming approach. We would like to know the rate of growth of both approaches. The simplest way to do so is by experiment. This problem will set up an experiment to compare the time used by both approaches. Again, you are not required to write everything. You can open the project in the folder Lab2 Prob2 to find the starting code. The given code already has two functions implementing Fibonacci sequences in both approaches. What you need to do is to measure the time used by both method for each Fibonacci number. The time used by both approaches should be written to a file named fibo.txt. Each line of the file must contain three numbers; the first number is the index of the Fibonacci number, the second number and the third number are times, in seconds, used to compute the Fibonacci number using Dynamic Programming approach and Recursive approach, respectively. The example of the first few lines is as follows *** TASK4: Modify the code to record the time used to compute each Fibonacci number from both approach to a file named fibo.txt *** *** TASK5: Draw a graph representing the time used by both approaches for each Fibonacci number. The x axis represents the index of Fibonacci while y axis represents the time used, in seconds. ***

11 Starting Code The starting code can be found in Folder Lab2 Prob2. Two Fibonacci calculation functions are already provided. Fibo() computes Fibonacci numbers using Dynamic Programming Approach while Fibo2() does the same thing using recursive approach. Notice that the code already prepares the file pointer for you but you have to write the result to the file yourself. Supplementary Explanation Time Measurement Real world running time of an algorithm can be done easily. Basically, one must measure the current time before the algorithm start and measure the current time again after the algorithm stop. The difference between the two measured timestamp is the time used by the algorithm. Windows provides a very simple method to measure the time. A Win32 API function GetTickCount() return a long integer containing the time, in millisecond, since the machine start. This function can be used easily to measure the time. The following code snippet shows how to compute the time used by function Algo1(). #include <windows.h> int main(int argc, char *argv[]) { long starttime; long stoptime; starttime1 = GetTickCount(); Algo1(); stoptime1 = GetTickCount(); // the starting time // the starting time // measure the time before Algo1() // call the algorithm // measure the time after Algo1() } // display the measured time frintf( used time = %f seconds, double(stoptime starttime) / ); return 0; Plotting Two Graphs in the Same Screen GNUPlot is capable of plotting several graphs at the same time. For example, a command plot sin(x), cos(x) produces two graph showing a sinusoidal and cosine function. To plot a data from a file but using data from different columns in each line, one can use the following command. plot fibo.txt using 1:2, fibo.txt using 1:3 The first part of the plot command ( fibo.txt using 1:2) tells GNUPlot that we want to plot the data in the file fibo.txt where the X value is taken from the 1 st column and the Y value is taken from the 2 nd column. This is indicated by the keyword using. Similarly, the second part of the

12 plot command ( fibo.txt using 1:3) tells GNUPlot that the X value and the Y value are taken from the 1 st column and the 3 rd column. GNUPlot can also change the type and style of displaying graph. For example, the above example plots the graph using a dot. To plot the just the second graph using a thicker line and different color, the following code can be used. plot "fibo.txt" using 1:3 with line linecolor 7 linewidth 4 Win32 API Windows comes with several functions allowing us to interact with the system. GetTickCount() is one of them. They are collectively called as Win32 API, the functions ranges from snooping system information such as CPU speed, the size of physical ram, getting the current time, name of attached printer, the MAC address, to manipulating the windows such that creating a process, changing security policy, deleting a file and much more. A reference to the available function can be found at us/library/aa383749(vs.85).aspx

13 Problem 3: FindMax Input: nothing Output: A file maxcount.txt containing the average number that the maximum value is changed in the problem of finding maximum value in a random array Objective The student can measure average performance of algorithm on several instances of problem The student can empirically compare running time of several algorithms Introduction In the previous two problems, we measure the resource used for each instant of the problem, i.e., we count the time used for each possible input of the problem. In most case, the problem consists of several input size where each input size also has several problem instances. Each instances of the same size might have different running time. In this problem, we interest in measuring average performance of the algorithm for each size of input. The problem we will consider is Find Max. Find Max is a simple problem of identifying the maximum value in the array. It can be done using the following simple code. typedef int* intarray; // define array of integer type /** * Finding the max value in the array * Input: * data : the array containing integer * count : the size of data * return: * the largest element in data */ int findmax(intarray data,int count) { //find the max value in the array int i; int max = INT_MIN; // iterator // variable holding the current maximum value, // initially set to the minimal value of int } // check from the first member to the last member // keep track of current max value in "max" variable for (i = 0;i < count;i++) { if (data[i] > max) { max = data[i]; } } return max;

14 The process is straightforward. The array is scanned from the first to the last element and we keep track of the largest value up to the point of scanning. At i th iteration, the variable max contains the maximum value from datat[0] to data[i 1]. Every time that data[i] is larger than max, max is updated to contain data[i]. Now, it is clear that we have to scan the entire length of the array. The time complexity of this algorithm is clearly θ(n). However, let us assume that the process of updating max variable is very time consuming. We wish to know how many times the variable max is updated. Obviously, this depends on the value of data. For example if data is sorted,.e.g., data ={1,2,3,4,5,6}, max is updated every time. In the other hand, if data is sorted backward, e.g., data = {6,5,4,3,2,1}, max is updated only once. The starting code of this problem is given in the Folder Lab2 Prob3. This code randomly generates several arrays ranging from size 100 to 10,000. For each specific size, 100 arrays are generated. We wish to count the averaged number that max is updated for each size. Additionally, we also wish to understand the relation between the size of input and the number that max is updated. You are also required to plot the graph showing that relation. Notice that the starting code already has the opened file pointer for you. *** TASK6: Modify the code to record the number that the variable max is updated. The code must compute the average number that max is updated per each size of input. The result should be stored in maxcount.txt *** *** TASK7: Draw a graph representing the relation between the number that max is updated and the size of the array. The x axis represents the size of input while y axis represents the average number that max is updated. *** Starting Code The starting code can be found in Folder Lab2 Prob3. The code already has all algorithms implemented. What you need to do is to count the time that the variable max is updated for each input size. You might need to create more variable somewhere to count that value and you also need to average it over several runs. Notice again that the code already prepare a file pointer for you. There are three functions in the main file. The randomdata(intarray *data,int count) function generates random data for the given size. No need is required for this function. The function int findmax(intarray data,int count) finds the maximum value in the array. This is where you should do the counting. You also need to modify the main() function to store the result into the file as well. The average of the data should be done here.

15 Grading Sheet Name:. Date:. ID: Section:. Time:. Lab 2 : Performance Measurement Task Grading Task Description Grader Signature Remark 1 Making output.txt 2 Creating Hailstone.txt 3 Plot the hailstone sequence 4 Creating fibo.txt 5 Plotting a graph comparing two approaches 6 Creating maxcount.txt 7 Plotting a graph for maxcount.txt Question 1. What should best describe the relation between the size of input in Find Max problem and the number that max is updated? Is it linear or quadratic or logarithmic or something else? 2. Write down the Hailstone sequence starting from number Which starting number of Hailstone sequences from 1 to 9,999 that resulting in longest sequence? How long is that sequence?

Introduction to Computing Systems Fall Lab # 3

Introduction to Computing Systems Fall Lab # 3 EE 1301 UMN Introduction to Computing Systems Fall 2013 Lab # 3 Collaboration is encouraged. You may discuss the problems with other students, but you must write up your own solutions, including all your

More information

Computer Science 322 Operating Systems Mount Holyoke College Spring Topic Notes: C and Unix Overview

Computer Science 322 Operating Systems Mount Holyoke College Spring Topic Notes: C and Unix Overview Computer Science 322 Operating Systems Mount Holyoke College Spring 2010 Topic Notes: C and Unix Overview This course is about operating systems, but since most of our upcoming programming is in C on a

More information

Computer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring Topic Notes: C and Unix Overview

Computer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring Topic Notes: C and Unix Overview Computer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring 2009 Topic Notes: C and Unix Overview This course is about computer organization, but since most of our programming is

More information

York University Faculty Science and Engineering Fall 2008

York University Faculty Science and Engineering Fall 2008 York University Faculty Science and Engineering Fall 2008 CSE2031 Final Software Tools Friday, Feb..26 th, 2008 Last Name 08:30 10:30am First name ID Instructions to students: Answer all questions. Marks

More information

PROGRAMMING IN C AND C++:

PROGRAMMING IN C AND C++: PROGRAMMING IN C AND C++: Week 1 1. Introductions 2. Using Dos commands, make a directory: C:\users\YearOfJoining\Sectionx\USERNAME\CS101 3. Getting started with Visual C++. 4. Write a program to print

More information

25.2 Opening and Closing a File

25.2 Opening and Closing a File Lecture 32 p.1 Faculty of Computer Science, Dalhousie University CSCI 2132 Software Development Lecture 32: Dynamically Allocated Arrays 26-Nov-2018 Location: Chemistry 125 Time: 12:35 13:25 Instructor:

More information

CpSc 1011 Lab 5 Conditional Statements, Loops, ASCII code, and Redirecting Input Characters and Hurricanes

CpSc 1011 Lab 5 Conditional Statements, Loops, ASCII code, and Redirecting Input Characters and Hurricanes CpSc 1011 Lab 5 Conditional Statements, Loops, ASCII code, and Redirecting Input Characters and Hurricanes Overview For this lab, you will use: one or more of the conditional statements explained below

More information

Lecture 03 Bits, Bytes and Data Types

Lecture 03 Bits, Bytes and Data Types Lecture 03 Bits, Bytes and Data Types Computer Languages A computer language is a language that is used to communicate with a machine. Like all languages, computer languages have syntax (form) and semantics

More information

MPATE-GE 2618: C Programming for Music Technology. Syllabus

MPATE-GE 2618: C Programming for Music Technology. Syllabus MPATE-GE 2618: C Programming for Music Technology Instructor Dr. Schuyler Quackenbush schuyler.quackenbush@nyu.edu Lab Teaching Assistant TBD Description Syllabus MPATE-GE 2618: C Programming for Music

More information

For Solved Question Papers of UGC-NET/GATE/SET/PGCET in Computer Science, visit

For Solved Question Papers of UGC-NET/GATE/SET/PGCET in Computer Science, visit For Solved Question Papers of UGC-NET/GATE/SET/PGCET in Computer Science, visit http://victory4sure.weebly.com/ For Solved Question Papers of UGC-NET/GATE/SET/PGCET in Computer Science, visit http://victory4sure.weebly.com/

More information

#23: Sequences March 28, 2009

#23: Sequences March 28, 2009 #23: Sequences March 28, 2009 a mysterious rule easy peasy Suppose n is an integer, and consider this simple rule: if n is even, divide it by two; otherwise, multiply n by 3, and add one. Pretty simple,

More information

ECE264 Fall 2013 Exam 1, September 24, 2013

ECE264 Fall 2013 Exam 1, September 24, 2013 ECE264 Fall 2013 Exam 1, September 24, 2013 In signing this statement, I hereby certify that the work on this exam is my own and that I have not copied the work of any other student while completing it.

More information

ECE264 Spring 2013 Exam 1, February 14, 2013

ECE264 Spring 2013 Exam 1, February 14, 2013 ECE264 Spring 2013 Exam 1, February 14, 2013 In signing this statement, I hereby certify that the work on this exam is my own and that I have not copied the work of any other student while completing it.

More information

Lab 4: Tracery Recursion in C with Linked Lists

Lab 4: Tracery Recursion in C with Linked Lists Lab 4: Tracery Recursion in C with Linked Lists For this lab we will be building on our previous lab at the end of the previous lab you should have had: #include #include char * make_string_from

More information

Writing to and reading from files

Writing to and reading from files Writing to and reading from files printf() and scanf() are actually short-hand versions of more comprehensive functions, fprintf() and fscanf(). The difference is that fprintf() includes a file pointer

More information

EL2310 Scientific Programming LAB2: C lab session. Patric Jensfelt, Andrzej Pronobis

EL2310 Scientific Programming LAB2: C lab session. Patric Jensfelt, Andrzej Pronobis EL2310 Scientific Programming LAB2: C lab session Patric Jensfelt, Andrzej Pronobis Chapter 1 Introduction 1.1 Reporting errors As any document, this document is likely to include errors and typos. Please

More information

File IO and command line input CSE 2451

File IO and command line input CSE 2451 File IO and command line input CSE 2451 File functions Open/Close files fopen() open a stream for a file fclose() closes a stream One character at a time: fgetc() similar to getchar() fputc() similar to

More information

Pointers and scanf() Steven R. Bagley

Pointers and scanf() Steven R. Bagley Pointers and scanf() Steven R. Bagley Recap Programs are a series of statements Defined in functions Can call functions to alter program flow if statement can determine whether code gets run Loops can

More information

UNIVERSITY OF NEBRASKA AT OMAHA Computer Science 4500/8506 Operating Systems Summer 2016 Programming Assignment 1 Introduction The purpose of this

UNIVERSITY OF NEBRASKA AT OMAHA Computer Science 4500/8506 Operating Systems Summer 2016 Programming Assignment 1 Introduction The purpose of this UNIVERSITY OF NEBRASKA AT OMAHA Computer Science 4500/8506 Operating Systems Summer 2016 Programming Assignment 1 Introduction The purpose of this programming assignment is to give you some experience

More information

Procedures, Parameters, Values and Variables. Steven R. Bagley

Procedures, Parameters, Values and Variables. Steven R. Bagley Procedures, Parameters, Values and Variables Steven R. Bagley Recap A Program is a sequence of statements (instructions) Statements executed one-by-one in order Unless it is changed by the programmer e.g.

More information

Kurt Schmidt. October 30, 2018

Kurt Schmidt. October 30, 2018 to Structs Dept. of Computer Science, Drexel University October 30, 2018 Array Objectives to Structs Intended audience: Student who has working knowledge of Python To gain some experience with a statically-typed

More information

Exercise Session 2 Systems Programming and Computer Architecture

Exercise Session 2 Systems Programming and Computer Architecture Systems Group Department of Computer Science ETH Zürich Exercise Session 2 Systems Programming and Computer Architecture Herbstsemester 216 Agenda Linux vs. Windows Working with SVN Exercise 1: bitcount()

More information

Content. Input Output Devices File access Function of File I/O Redirection Command-line arguments

Content. Input Output Devices File access Function of File I/O Redirection Command-line arguments File I/O Content Input Output Devices File access Function of File I/O Redirection Command-line arguments UNIX and C language C is a general-purpose, high-level language that was originally developed by

More information

Note: This is a miniassignment and the grading is automated. If you do not submit it correctly, you will receive at most half credit.

Note: This is a miniassignment and the grading is automated. If you do not submit it correctly, you will receive at most half credit. Com S 227 Fall 2017 Miniassignment 1 50 points Due Date: Monday, October 16, 11:59 pm (midnight) Late deadline (25% penalty): Tuesday, October 17, 11:59 pm General information This assignment is to be

More information

Model Viva Questions for Programming in C lab

Model Viva Questions for Programming in C lab Model Viva Questions for Programming in C lab Title of the Practical: Assignment to prepare general algorithms and flow chart. Q1: What is a flowchart? A1: A flowchart is a diagram that shows a continuous

More information

CS2 Practical 6 CS2Bh 24 January 2005

CS2 Practical 6 CS2Bh 24 January 2005 CS2 Practical 6 Data Structures for Dictionaries This practical is based on material of the Algorithms and Data Structures thread. It has two parts: Part A, worth 40 marks, consists of four pen-and-paper

More information

Chapter 1 - What s in a program?

Chapter 1 - What s in a program? Chapter 1 - What s in a program? I. Student Learning Outcomes (SLOs) a. You should be able to use Input-Process-Output charts to define basic processes in a programming module. b. You should be able to

More information

CpSc 1011 Lab 3 Integer Variables, Mathematical Operations, & Redirection

CpSc 1011 Lab 3 Integer Variables, Mathematical Operations, & Redirection CpSc 1011 Lab 3 Integer Variables, Mathematical Operations, & Redirection Overview By the end of the lab, you will be able to: declare variables perform basic arithmetic operations on integer variables

More information

Faculty of Engineering Computer Engineering Department Islamic University of Gaza C++ Programming Language Lab # 6 Functions

Faculty of Engineering Computer Engineering Department Islamic University of Gaza C++ Programming Language Lab # 6 Functions Faculty of Engineering Computer Engineering Department Islamic University of Gaza 2013 C++ Programming Language Lab # 6 Functions C++ Programming Language Lab # 6 Functions Objective: To be familiar with

More information

File I/O. Arash Rafiey. November 7, 2017

File I/O. Arash Rafiey. November 7, 2017 November 7, 2017 Files File is a place on disk where a group of related data is stored. Files File is a place on disk where a group of related data is stored. C provides various functions to handle files

More information

Lab Session # 6 Functions. ALQUDS University Department of Computer Engineering

Lab Session # 6 Functions. ALQUDS University Department of Computer Engineering 2013/2014 Programming Fundamentals for Engineers Lab Lab Session # 6 Functions ALQUDS University Department of Computer Engineering Objective: After completing this lab, the students should be able to:

More information

Midterm I Exam Principles of Imperative Computation Frank Pfenning. February 17, 2011

Midterm I Exam Principles of Imperative Computation Frank Pfenning. February 17, 2011 Midterm I Exam 15-122 Principles of Imperative Computation Frank Pfenning February 17, 2011 Name: Sample Solution Andrew ID: fp Section: Instructions This exam is closed-book with one sheet of notes permitted.

More information

Lecture 12 CSE July Today we ll cover the things that you still don t know that you need to know in order to do the assignment.

Lecture 12 CSE July Today we ll cover the things that you still don t know that you need to know in order to do the assignment. Lecture 12 CSE 110 20 July 1992 Today we ll cover the things that you still don t know that you need to know in order to do the assignment. 1 The NULL Pointer For each pointer type, there is one special

More information

ECE264 Spring 2013 Final Exam, April 30, 2013

ECE264 Spring 2013 Final Exam, April 30, 2013 ECE264 Spring 2013 Final Exam, April 30, 2013 In signing this statement, I hereby certify that the work on this exam is my own and that I have not copied the work of any other student while completing

More information

Exam Principles of Imperative Computation, Summer 2011 William Lovas. June 24, 2011

Exam Principles of Imperative Computation, Summer 2011 William Lovas. June 24, 2011 Exam 3 15-122 Principles of Imperative Computation, Summer 2011 William Lovas June 24, 2011 Name: Andrew ID: Instructions This exam is closed-book with one double-sided sheet of notes permitted. You have

More information

Math 3 Coordinate Geometry Part 2 Graphing Solutions

Math 3 Coordinate Geometry Part 2 Graphing Solutions Math 3 Coordinate Geometry Part 2 Graphing Solutions 1 SOLVING SYSTEMS OF EQUATIONS GRAPHICALLY The solution of two linear equations is the point where the two lines intersect. For example, in the graph

More information

I2204 ImperativeProgramming Semester: 1 Academic Year: 2018/2019 Credits: 5 Dr Antoun Yaacoub

I2204 ImperativeProgramming Semester: 1 Academic Year: 2018/2019 Credits: 5 Dr Antoun Yaacoub Lebanese University Faculty of Science Computer Science BS Degree I2204 ImperativeProgramming Semester: 1 Academic Year: 2018/2019 Credits: 5 Dr Antoun Yaacoub I2204- Imperative Programming Schedule 08h00-09h40

More information

Guidelines for Writing Mathematical Proofs

Guidelines for Writing Mathematical Proofs Appendix A Guidelines for Writing Mathematical Proofs One of the most important forms of mathematical writing is writing mathematical proofs. The writing of mathematical proofs is an acquired skill and

More information

Section 7.6 Graphs of the Sine and Cosine Functions

Section 7.6 Graphs of the Sine and Cosine Functions Section 7.6 Graphs of the Sine and Cosine Functions We are going to learn how to graph the sine and cosine functions on the xy-plane. Just like with any other function, it is easy to do by plotting points.

More information

CpSc 1111 Lab 4 Part a Flow Control, Branching, and Formatting

CpSc 1111 Lab 4 Part a Flow Control, Branching, and Formatting CpSc 1111 Lab 4 Part a Flow Control, Branching, and Formatting Your factors.c and multtable.c files are due by Wednesday, 11:59 pm, to be submitted on the SoC handin page at http://handin.cs.clemson.edu.

More information

Intermediate Programming Programming-Tools and Sorting-Algorithms Exercise Sheet Deadline on 13th of November 2009

Intermediate Programming Programming-Tools and Sorting-Algorithms Exercise Sheet Deadline on 13th of November 2009 Institute of Scientific Computing Technische Universität Braunschweig Prof. Hermann G. Matthies, Ph. D. Dominik Jürgens Winter Term 2009 August 11, 2009 Intermediate Programming Programming-Tools and Sorting-Algorithms

More information

UNIVERSITY OF NEBRASKA AT OMAHA Computer Science 4500/8506 Operating Systems Fall Programming Assignment 1 (updated 9/16/2017)

UNIVERSITY OF NEBRASKA AT OMAHA Computer Science 4500/8506 Operating Systems Fall Programming Assignment 1 (updated 9/16/2017) UNIVERSITY OF NEBRASKA AT OMAHA Computer Science 4500/8506 Operating Systems Fall 2017 Programming Assignment 1 (updated 9/16/2017) Introduction The purpose of this programming assignment is to give you

More information

Computing Fundamentals 2 Introduction to CafeOBJ

Computing Fundamentals 2 Introduction to CafeOBJ Computing Fundamentals 2 Introduction to CafeOBJ Lecturer: Patrick Browne Lecture Room: K408 Lab Room: A308 Based on work by: Nakamura Masaki, João Pascoal Faria, Prof. Heinrich Hußmann. See notes on slides

More information

1 Introduction to Matlab

1 Introduction to Matlab 1 Introduction to Matlab 1. What is Matlab? Matlab is a computer program designed to do mathematics. You might think of it as a super-calculator. That is, once Matlab has been started, you can enter computations,

More information

(Refer Slide Time: 1:27)

(Refer Slide Time: 1:27) Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture 1 Introduction to Data Structures and Algorithms Welcome to data

More information

Reading 8 : Recursion

Reading 8 : Recursion CS/Math 40: Introduction to Discrete Mathematics Fall 015 Instructors: Beck Hasti, Gautam Prakriya Reading 8 : Recursion 8.1 Recursion Recursion in computer science and mathematics refers to the idea of

More information

UNIVERSITY OF ENGINEERING & MANAGEMENT, KOLKATA C ASSIGNMENTS

UNIVERSITY OF ENGINEERING & MANAGEMENT, KOLKATA C ASSIGNMENTS UNIVERSITY OF ENGINEERING & MANAGEMENT, KOLKATA C ASSIGNMENTS All programs need to be submitted on 7th Oct 206 by writing in hand written format in A4 sheet. Flowcharts, algorithms, source codes and outputs

More information

Lab 2: Structured Program Development in C

Lab 2: Structured Program Development in C Lab 2: Structured Program Development in C (Part A: Your first C programs - integers, arithmetic, decision making, Part B: basic problem-solving techniques, formulating algorithms) Learning Objectives

More information

6.001 Notes: Section 4.1

6.001 Notes: Section 4.1 6.001 Notes: Section 4.1 Slide 4.1.1 In this lecture, we are going to take a careful look at the kinds of procedures we can build. We will first go back to look very carefully at the substitution model,

More information

Pointer Casts and Data Accesses

Pointer Casts and Data Accesses C Programming Pointer Casts and Data Accesses For this assignment, you will implement a C function similar to printf(). While implementing the function you will encounter pointers, strings, and bit-wise

More information

Informatica e Sistemi in Tempo Reale

Informatica e Sistemi in Tempo Reale Informatica e Sistemi in Tempo Reale Introduction to C programming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 5, 2011 G. Lipari (Scuola Superiore Sant Anna) Introduction

More information

Functions. Lab 4. Introduction: A function : is a collection of statements that are grouped together to perform an operation.

Functions. Lab 4. Introduction: A function : is a collection of statements that are grouped together to perform an operation. Lab 4 Functions Introduction: A function : is a collection of statements that are grouped together to perform an operation. The following is its format: type name ( parameter1, parameter2,...) { statements

More information

Fundamentals of Programming

Fundamentals of Programming Fundamentals of Programming Introduction to the C language Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 29, 2012 G. Lipari (Scuola Superiore Sant Anna) The C language

More information

Programming with Arrays Intro to Pointers CS 16: Solving Problems with Computers I Lecture #11

Programming with Arrays Intro to Pointers CS 16: Solving Problems with Computers I Lecture #11 Programming with Arrays Intro to Pointers CS 16: Solving Problems with Computers I Lecture #11 Ziad Matni Dept. of Computer Science, UCSB Thursday, 5/17 in this classroom Starts at 2:00 PM **SHARP** Please

More information

RECURSION AND LINKED LISTS 3

RECURSION AND LINKED LISTS 3 RECURSION AND LINKED LISTS 3 COMPUTER SCIENCE 61A July 1, 2014 1 Termination and Warmup A function is recursive if executing a call to the function requires another call to the same function, called a

More information

Objectives. Part 1: forward kinematics. Physical Dimension

Objectives. Part 1: forward kinematics. Physical Dimension ME 446 Laboratory #1 Kinematic Transformations Report is due at the beginning of your lab time the week of February 20 th. One report per group. Lab sessions will be held the weeks of January 23 rd, January

More information

ECE264 Summer 2013 Exam 1, June 20, 2013

ECE264 Summer 2013 Exam 1, June 20, 2013 ECE26 Summer 2013 Exam 1, June 20, 2013 In signing this statement, I hereby certify that the work on this exam is my own and that I have not copied the work of any other student while completing it. I

More information

C introduction: part 1

C introduction: part 1 What is C? C is a compiled language that gives the programmer maximum control and efficiency 1. 1 https://computer.howstuffworks.com/c1.htm 2 / 26 3 / 26 Outline Basic file structure Main function Compilation

More information

Lab # 4. Files & Queues in C

Lab # 4. Files & Queues in C Islamic University of Gaza Faculty of Engineering Department of Computer Engineering ECOM 4010: Lab # 4 Files & Queues in C Eng. Haneen El-Masry October, 2013 2 FILE * Files in C For C File I/O you need

More information

Reference and Style Guide for Microsoft Excel

Reference and Style Guide for Microsoft Excel Reference and Style Guide for Microsoft Excel TABLE OF CONTENTS Getting Acquainted 2 Basic Excel Features 2 Writing Cell Equations Relative and Absolute Addresses 3 Selecting Cells Highlighting, Moving

More information

Each line will contain a string ("even" or "odd"), followed by one or more spaces, followed by a nonnegative integer.

Each line will contain a string (even or odd), followed by one or more spaces, followed by a nonnegative integer. Decision-making in C Squeezing Digits out of an Integer Assignment For part of this assignment, you will use very basic C techniques to implement a C function to remove from a given nonnegative integer

More information

FIT 100. Lab 8: Writing and Running Your First Visual Basic Program Spring 2002

FIT 100. Lab 8: Writing and Running Your First Visual Basic Program Spring 2002 FIT 100 Lab 8: Writing and Running Your First Visual Basic Program Spring 2002 1. Create a New Project and Form... 1 2. Add Objects to the Form and Name Them... 3 3. Manipulate Object Properties... 3 4.

More information

Tips from the experts: How to waste a lot of time on this assignment

Tips from the experts: How to waste a lot of time on this assignment Com S 227 Spring 2018 Assignment 1 100 points Due Date: Friday, September 14, 11:59 pm (midnight) Late deadline (25% penalty): Monday, September 17, 11:59 pm General information This assignment is to be

More information

2009 S2 COMP File Operations

2009 S2 COMP File Operations 2009 S2 COMP1921 9. File Operations Oliver Diessel odiessel@cse.unsw.edu.au Last updated: 16:00 22 Sep 2009 9. File Operations Topics to be covered: Streams Text file operations Binary file operations

More information

15-122: Principles of Imperative Computation, Fall 2015

15-122: Principles of Imperative Computation, Fall 2015 15-122 Programming 5 Page 1 of 10 15-122: Principles of Imperative Computation, Fall 2015 Homework 5 Programming: Clac Due: Thursday, October 15, 2015 by 22:00 In this assignment, you will implement a

More information

PROGRAMMAZIONE I A.A. 2017/2018

PROGRAMMAZIONE I A.A. 2017/2018 PROGRAMMAZIONE I A.A. 2017/2018 INPUT/OUTPUT INPUT AND OUTPUT Programs must be able to write data to files or to physical output devices such as displays or printers, and to read in data from files or

More information

ECE 2035 Programming HW/SW Systems Spring problems, 7 pages Exam One Solutions 4 February 2013

ECE 2035 Programming HW/SW Systems Spring problems, 7 pages Exam One Solutions 4 February 2013 Problem 1 (3 parts, 30 points) Code Fragments Part A (5 points) Write a MIPS code fragment that branches to label Target when register $1 is less than or equal to register $2. You may use only two instructions.

More information

CS 261 Data Structures. Big-Oh Analysis: A Review

CS 261 Data Structures. Big-Oh Analysis: A Review CS 261 Data Structures Big-Oh Analysis: A Review Big-Oh: Purpose How can we characterize the runtime or space usage of an algorithm? We want a method that: doesn t depend upon hardware used (e.g., PC,

More information

Introduction to file management

Introduction to file management 1 Introduction to file management Some application require input to be taken from a file and output is required to be stored in a file. The C language provides the facility of file input-output operations.

More information

Visualisation Lab: gnuplot

Visualisation Lab: gnuplot Visualisation Lab: gnuplot Anton Gerdelan February 2, 2012 What is gnuplot? gnuplot is a tool for creating graphs and charts. gnuplot has a terminal. You can enter commands to tell gnuplot how to format

More information

Creating a Shell or Command Interperter Program CSCI411 Lab

Creating a Shell or Command Interperter Program CSCI411 Lab Creating a Shell or Command Interperter Program CSCI411 Lab Adapted from Linux Kernel Projects by Gary Nutt and Operating Systems by Tannenbaum Exercise Goal: You will learn how to write a LINUX shell

More information

CS 142 Style Guide Grading and Details

CS 142 Style Guide Grading and Details CS 142 Style Guide Grading and Details In the English language, there are many different ways to convey a message or idea: some ways are acceptable, whereas others are not. Similarly, there are acceptable

More information

CpSc 111 Lab 5 Conditional Statements, Loops, the Math Library, and Redirecting Input

CpSc 111 Lab 5 Conditional Statements, Loops, the Math Library, and Redirecting Input CpSc Lab 5 Conditional Statements, Loops, the Math Library, and Redirecting Input Overview For this lab, you will use: one or more of the conditional statements explained below scanf() or fscanf() to read

More information

Deep Learning for Visual Computing Prof. Debdoot Sheet Department of Electrical Engineering Indian Institute of Technology, Kharagpur

Deep Learning for Visual Computing Prof. Debdoot Sheet Department of Electrical Engineering Indian Institute of Technology, Kharagpur Deep Learning for Visual Computing Prof. Debdoot Sheet Department of Electrical Engineering Indian Institute of Technology, Kharagpur Lecture - 05 Classification with Perceptron Model So, welcome to today

More information

CE221 Programming in C++ Part 1 Introduction

CE221 Programming in C++ Part 1 Introduction CE221 Programming in C++ Part 1 Introduction 06/10/2017 CE221 Part 1 1 Module Schedule There are two lectures (Monday 13.00-13.50 and Tuesday 11.00-11.50) each week in the autumn term, and a 2-hour lab

More information

Main Program. C Programming Notes. #include <stdio.h> main() { printf( Hello ); } Comments: /* comment */ //comment. Dr. Karne Towson University

Main Program. C Programming Notes. #include <stdio.h> main() { printf( Hello ); } Comments: /* comment */ //comment. Dr. Karne Towson University C Programming Notes Dr. Karne Towson University Reference for C http://www.cplusplus.com/reference/ Main Program #include main() printf( Hello ); Comments: /* comment */ //comment 1 Data Types

More information

CSE Theory of Computing Fall 2017 Project 4-Combinator Project

CSE Theory of Computing Fall 2017 Project 4-Combinator Project CSE 30151 Theory of Computing Fall 2017 Project 4-Combinator Project Version 1: Nov. 20, 2017 1 Overview At this point you understand computations that happen as planned series of individual steps where

More information

Programming in C. Session 8. Seema Sirpal Delhi University Computer Centre

Programming in C. Session 8. Seema Sirpal Delhi University Computer Centre Programming in C Session 8 Seema Sirpal Delhi University Computer Centre File I/O & Command Line Arguments An important part of any program is the ability to communicate with the world external to it.

More information

Introduction to Scientific Computing

Introduction to Scientific Computing Introduction to Scientific Computing Dr Hanno Rein Last updated: October 12, 2018 1 Computers A computer is a machine which can perform a set of calculations. The purpose of this course is to give you

More information

Dynamic memory allocation

Dynamic memory allocation Dynamic memory allocation outline Memory allocation functions Array allocation Matrix allocation Examples Memory allocation functions (#include ) malloc() Allocates a specified number of bytes

More information

BLM2031 Structured Programming. Zeyneb KURT

BLM2031 Structured Programming. Zeyneb KURT BLM2031 Structured Programming Zeyneb KURT 1 Contact Contact info office : D-219 e-mail zeynebkurt@gmail.com, zeyneb@ce.yildiz.edu.tr When to contact e-mail first, take an appointment What to expect help

More information

CS 415 Midterm Exam Spring SOLUTION

CS 415 Midterm Exam Spring SOLUTION CS 415 Midterm Exam Spring 2005 - SOLUTION Name Email Address Student ID # Pledge: This exam is closed note, closed book. Questions will be graded on quality of answer. Please supply the best answer you

More information

Pick any positive integer. If the integer is even, divide it by 2. If it is odd,

Pick any positive integer. If the integer is even, divide it by 2. If it is odd, Equal Groups Multiplying and Dividing Integers Learning Goals In this lesson, you will: Multiply integers. Divide integers. Pick any positive integer. If the integer is even, divide it by 2. If it is odd,

More information

Snowflake Numbers. A look at the Collatz Conjecture in a recreational manner. By Sir Charles W. Shults III

Snowflake Numbers. A look at the Collatz Conjecture in a recreational manner. By Sir Charles W. Shults III Snowflake Numbers A look at the Collatz Conjecture in a recreational manner By Sir Charles W. Shults III For many people, mathematics is something dry and of little interest. I ran across the mention of

More information

Exam Principles of Imperative Computation, Summer 2011 William Lovas. June 24, 2011

Exam Principles of Imperative Computation, Summer 2011 William Lovas. June 24, 2011 Exam 3 15-122 Principles of Imperative Computation, Summer 2011 William Lovas June 24, 2011 Name: Sample Solution Andrew ID: wlovas Instructions This exam is closed-book with one double-sided sheet of

More information

Project 1. due date Sunday July 8, 2018, 12:00 noon

Project 1. due date Sunday July 8, 2018, 12:00 noon Queens College, CUNY, Department of Computer Science Object-oriented programming in C++ CSCI 211 / 611 Summer 2018 Instructor: Dr. Sateesh Mane c Sateesh R. Mane 2018 Project 1 due date Sunday July 8,

More information

UNIX input and output

UNIX input and output UNIX input and output Disk files In UNIX a disk file is a finite sequence of bytes, usually stored on some nonvolatile medium. Disk files have names, which are called paths. We won t discuss file naming

More information

4. Use a loop to print the first 25 Fibonacci numbers. Do you need to store these values in a data structure such as an array or list?

4. Use a loop to print the first 25 Fibonacci numbers. Do you need to store these values in a data structure such as an array or list? 1 Practice problems Here is a collection of some relatively straightforward problems that let you practice simple nuts and bolts of programming. Each problem is intended to be a separate program. 1. Write

More information

Lab1: Use of Word and Excel

Lab1: Use of Word and Excel Dr. Fritz Wilhelm; physics 230 Lab1: Use of Word and Excel Page 1 of 9 Lab partners: Download this page onto your computer. Also download the template file which you can use whenever you start your lab

More information

Midterm Exam Nov 8th, COMS W3157 Advanced Programming Columbia University Fall Instructor: Jae Woo Lee.

Midterm Exam Nov 8th, COMS W3157 Advanced Programming Columbia University Fall Instructor: Jae Woo Lee. Midterm Exam Nov 8th, 2012 COMS W3157 Advanced Programming Columbia University Fall 2012 Instructor: Jae Woo Lee About this exam: - There are 4 problems totaling 100 points: problem 1: 30 points problem

More information

211: Computer Architecture Summer 2016

211: Computer Architecture Summer 2016 211: Computer Architecture Summer 2016 Liu Liu Topic: C Programming Data Representation I/O: - (example) cprintf.c Memory: - memory address - stack / heap / constant space - basic data layout Pointer:

More information

CSE 303 Midterm Exam

CSE 303 Midterm Exam CSE 303 Midterm Exam October 29, 2008 Name Sample Solution The exam is closed book, except that you may have a single page of hand written notes for reference. If you don t remember the details of how

More information

Darshan Institute of Engineering & Technology for Diploma Studies Unit 6

Darshan Institute of Engineering & Technology for Diploma Studies Unit 6 1. What is File management? In real life, we want to store data permanently so that later on we can retrieve it and reuse it. A file is a collection of bytes stored on a secondary storage device like hard

More information

CIS220 In Class/Lab 1: Due Sunday night at midnight. Submit all files through Canvas (25 pts)

CIS220 In Class/Lab 1: Due Sunday night at midnight. Submit all files through Canvas (25 pts) CIS220 In Class/Lab 1: Due Sunday night at midnight. Submit all files through Canvas (25 pts) Problem 0: Install Eclipse + CDT (or, as an alternative, Netbeans). Follow the instructions on my web site.

More information

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture 04 Programs with IO and Loop We will now discuss the module 2,

More information

Subject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100

Subject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100 Code: DC-05 Subject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100 NOTE: There are 11 Questions in all. Question 1 is compulsory and carries 16 marks. Answer to Q. 1. must be written in the space

More information

CSE413 Midterm. Question Max Points Total 100

CSE413 Midterm. Question Max Points Total 100 CSE413 Midterm 05 November 2007 Name Student ID Answer all questions; show your work. You may use: 1. The Scheme language definition. 2. One 8.5 * 11 piece of paper with handwritten notes Other items,

More information

Algorithm Analysis CISC4080 CIS, Fordham Univ. Instructor: X. Zhang

Algorithm Analysis CISC4080 CIS, Fordham Univ. Instructor: X. Zhang Algorithm Analysis CISC4080 CIS, Fordham Univ. Instructor: X. Zhang Last class Review some algorithms learned in previous classes idea => pseudocode => implementation Correctness? Three sorting algorithms:

More information

CpSc 1111 Lab 6 Conditional Statements, Loops, the Math Library, and Random Numbers What s the Point?

CpSc 1111 Lab 6 Conditional Statements, Loops, the Math Library, and Random Numbers What s the Point? CpSc 1111 Lab 6 Conditional Statements, Loops, the Math Library, and Random Numbers What s the Point? Overview For this lab, you will use: one or more of the conditional statements explained below scanf()

More information

Algorithm Analysis. Applied Algorithmics COMP526. Algorithm Analysis. Algorithm Analysis via experiments

Algorithm Analysis. Applied Algorithmics COMP526. Algorithm Analysis. Algorithm Analysis via experiments Applied Algorithmics COMP526 Lecturer: Leszek Gąsieniec, 321 (Ashton Bldg), L.A.Gasieniec@liverpool.ac.uk Lectures: Mondays 4pm (BROD-107), and Tuesdays 3+4pm (BROD-305a) Office hours: TBA, 321 (Ashton)

More information