Programming Assignment #4 Arrays and Pointers

Size: px
Start display at page:

Download "Programming Assignment #4 Arrays and Pointers"

Transcription

1 CS-2301, System Programming for Non-majors, B-term 2013 Project 4 (30 points) Assigned: Tuesday, November 19, 2013 Due: Tuesday, November 26, Noon Abstract Programming Assignment #4 Arrays and Pointers Develop a Monte Carlo simulation of the game of craps to learn more about the game s behavior. Outcomes After successfully completing this assignment, you should be able to: Create arrays of data Pass arrays as arguments to functions Allow functions to modify the contents of arrays Use pointer arithmetic for arrays Build a multi-file application in C Use makefiles to correctly build, rebuild, and clean your working directory Background Read the sections of your textbook on pointers and arrays. To better understand the Bubble Sort algorithm, consult Wikipedia or other resources. A Monte Carlo simulation is a program that runs many times with random inputs in order to gather a statistical picture of its outputs. Monte Carlo simulations are widely used in business and engineering when it is impossible or too difficult to model problems, systems, investment strategies, etc., or when the problems have too many degrees of freedom for an analysis in closed form. In this assignment, the problem is the game of craps. Your program should enable you to discover how frequently the player wins versus loses, whether a game with many rolls of the dice favors the player or the house, and other useful information that a gambler would like to know. This Assignment Create a new program called montecarlo based on at least three C files, two header files, and one makefile. Copy the functions playgame and rolldice from Programming Assignment #3 into a new file named, for example, playcraps.c. Create a new header file, playcraps.h, that contains the function prototype of playgame and anything else needed by a caller of playgame for example, to initialize (i.e., seed ) the random number generator. Modify playgame so that (a) it does not print anything, and (b) it returns an integer reflecting both the number of throws of the dice and whether the game was won or lost. In particular, if the player wins a game after n throws, it should return the integer value n. If the player loses after n throws, it should return the integer value n. Project 4 1

2 In one or more new.c files, create the following functions: A function that prompts the user for the number of games of craps to play and then plays that number of games without human intervention (i.e., by calling playgame). It stores the results of the games in an appropriately-sized array, one element per game. In particular, the number of elements in the array should be exactly the number of games entered by the user. A function to print out the number of games played and compute the mean and median numbers of throws required for a game to be won or lost. A function to analyze the array of results and print out answers to the questions listed below. The main() function, that controls all of the others. In particular, main or one of the functions it calls must allocate and free any arrays that it needs. Construct a makefile patterned after Lab #4 to build the montecarlo program and all of its components. Make sure that $(CFLAGS) is specified in the commands to build individual modules and that it defaults to g -Wall. Be sure that your makefile rebuilds only those files that are necessary and that it can make your directory clean. For the analysis portion of this assignment, your program needs to print out answers to the following questions: 1. What is the probability that the player wins a game of craps? 2. What percentage of games are won on the first throw, second throw, third throw,, twentieth throw, and after the twentieth throw? (The sum of these percentages should total to the probability in Question 1, expressed as a percentage.) 3. What percentage of games are lost on the first throw, second throw, third throw,, twentieth throw, and after the twentieth throw? (The sum of these percentages, when added to the probability in Question 1 expressed as a percentage, should total 100%.) 4. Do the chances of winning improve with the length of the game? In particular, for questions 2 and 3, print out a table showing the number of throws and for each number of throws, the percentages of games with that number of throws that are won and lost. You may need to construct another array to generate this data. Test and debug your program with at least 1000 games. After you have debugged your program, modify it to seed the random number generator with the time of day and test it again. Be sure that the program you turn in is seeded with the time. Finally, run the program 8 times, saving the output in a file, with two runs each of 100, 500, 1000, and 5000 games. Turn this file in with your program and README file, and in the README file summarize what you see in these experiments. What sort of differences do you see when repeating with the same number of games and different seeds? What variability do you see as you increase the number of games? Include Files needed by your Programs stdio.h provides printf, scanf, getchar stdlib.h provides rand, srand, and abs math.h provides sqrt time.h provides time, which is used to seed the random number generator You may wish to consult the man pages for some these functions. In a Linux command shell (e.g., your PuTTY, X-Win32, or SSH window), type man abs man rand man srand Project 4 2

3 man sqrt Note that the time function is a little different in the man page system, because there are several of them. If you simply type man time, you will get information for the time shell command i.e., a command that tells you how long it takes to execute another command. This is not what you want. Instead, type man 2 time This tells the man page system to give you information about time function defined in Section 2 of the man pages, where most of the functions are defined. In general, if you simply ask the man page system for information about command xyz, it will provide you with the information matching xyz in the lowest numbered section. If you want something from another section, you have to specifically provide the section number. More information about the man page system can be found by typing the following to a Linux command prompt: man man man apropos Means and Medians and Standard Deviations Means, medians, and standard deviations are commonly used in engineering and scientific calculations. The mean number of throws is easy to calculate. Simply add up the number of throws in the array and divide by the number of games. Be sure you take the absolute value of the number of throws, so that losing games do not cancel winning ones. To calculate the median, you must sort the array. If a sorted array A has n elements, the median is defined as A[n/2] if n is odd and as (A[n/2-1] + A[n/2])/2.0 if n is even. (This particular definition of the median is based on the fact that arrays in C are indexed from zero.) You may sort the array using the Bubble Sort algorithm, shown here: void BubbleSort (int A[], const int arraysize) { int i, j; for(i = 0; i < arraysize; i++) for(j = 0; j < arraysize-1; j++) if(abs(a[j]) > abs(a[j+1])) swap(a+j, A+j+1); } // void BubbleSort( ) Note that this algorithm sorts the array A in place. Note also that it sorts by the absolute values of the elements of A. Finally, note that it uses array arithmetic to pass pointers to the swap function. The swap function is void swap (int *a, int *b) { int temp = *a; *a = *b; *b = temp; } // void swap( ) It is best to put the BubbleSort and swap functions in its own.c file called bubblesort.c. To make BubbleSort available, there should also be a bubblesort.h file. Note that the swap function should not be mentioned in bubblesort.h, because that is strictly internal to the implementation of Bubble Sort and won t be called independently by any other program. Project 4 3

4 The standard deviation is the square root of the variance. The variance is the average of the squared distance between each value and its mean. Thus with count entries in the list and a mean value of ave, the variance = [ ] /count. The square root function sqrt() expects a double value as input and returns a double value. Deliverables You should write a short README file in.txt,.doc, or.pdf format, to be submitted with your program. In this file, you should document the pre- and post-conditions of all functions and the loop invariants of all loops. You should also include your analysis of the data file from your experiments. This assignment is named PA4 in the web-based Turnin system. You can access Turnin from any browser at the following URL: Be sure to put your name at the top of ALL files, including all code, header, and data files! You would be surprised by how many students forget this. Programs submitted after Noon on November 26 will be tagged as late, and will be subject to the late assignment policy. Grading This assignment is worth thirty (30) points. Your program must compile without errors in order to receive any credit. It is suggested that before your submit your program, compile it again on a CCC system to be sure that it does not blow up or contain surprising warnings. Program organization into three or more.c files, two or more.h file(s), and a makefile 4 points. Note: The.c files should include at least playgame.c (or whatever you wish to call it), the new.c file that sets up the array and plays the requested number of games, and your sort function (Bubblesort or otherwise). The first target of the makefile should be a program file called montecarlo. Correct compilation without warnings using make and correct operation of make for individual files and for clean 4 points Correctly allocating an array of n elements, correctly playing the game n times, correctly storing the results in the array, correctly freeing the array at the end 5 points Correctly sorting the array and obtaining the mean, median, and standard deviation on the number of throws 4 points Building a table or other suitable data structure to answer the four questions, printing out those results, and getting answers consistent with the TAs test cases 5 points Creating a data file with the output of 8 runs of your program 4 points Satisfactory README file, including loop invariants for all loops and pre-and post-conditions on all functions and analysis of data 4 points In addition, the correct usage of a makefile to build your system completes the requirements of Lab 4. Extra credit For five points extra credit, modify your main program to accept two optional command line arguments according to 5.10 of Kernighan and Ritchie. The command line arguments are numberof- Games and SeedValue. If one argument is specified, don t prompt the user for the number of games, but simply use the number in the command argument and print out a message saying so. If a Project 4 4

5 second argument is specified, use its number as the seed instead of the time. For example, your command line might be./montecarlo This instructs montecarlo to play 1000 games and to seed the random number generator with the value As with all assignments, be sure to get the required part of the assignment working before attempting to modify it to accept command line arguments. Project 4 5

Programming Assignment #3 Event Driven Simulation

Programming Assignment #3 Event Driven Simulation CS-2303, System Programming Concepts, A-term 2012 Project 3 (45 points) Assigned: Friday, September 7, 2012 Due: Friday, September 14, 2012, 11:59 PM Abstract Programming Assignment #3 Event Driven Simulation

More information

C Functions. 5.2 Program Modules in C

C Functions. 5.2 Program Modules in C 1 5 C Functions 5.2 Program Modules in C 2 Functions Modules in C Programs combine user-defined functions with library functions - C standard library has a wide variety of functions Function calls Invoking

More information

Lecture 04 FUNCTIONS AND ARRAYS

Lecture 04 FUNCTIONS AND ARRAYS Lecture 04 FUNCTIONS AND ARRAYS 1 Motivations Divide hug tasks to blocks: divide programs up into sets of cooperating functions. Define new functions with function calls and parameter passing. Use functions

More information

Function Call Stack and Activation Records

Function Call Stack and Activation Records 71 Function Call Stack and Activation Records To understand how C performs function calls, we first need to consider a data structure (i.e., collection of related data items) known as a stack. Students

More information

Functions. Computer System and programming in C Prentice Hall, Inc. All rights reserved.

Functions. Computer System and programming in C Prentice Hall, Inc. All rights reserved. Functions In general, functions are blocks of code that perform a number of pre-defined commands to accomplish something productive. You can either use the built-in library functions or you can create

More information

EAS230: Programming for Engineers Lab 1 Fall 2004

EAS230: Programming for Engineers Lab 1 Fall 2004 Lab1: Introduction Visual C++ Objective The objective of this lab is to teach students: To work with the Microsoft Visual C++ 6.0 environment (referred to as VC++). C++ program structure and basic input

More information

Lecture 3. Review. CS 141 Lecture 3 By Ziad Kobti -Control Structures Examples -Built-in functions. Conditions: Loops: if( ) / else switch

Lecture 3. Review. CS 141 Lecture 3 By Ziad Kobti -Control Structures Examples -Built-in functions. Conditions: Loops: if( ) / else switch Lecture 3 CS 141 Lecture 3 By Ziad Kobti -Control Structures Examples -Built-in functions Review Conditions: if( ) / else switch Loops: for( ) do...while( ) while( )... 1 Examples Display the first 10

More information

Dr M Kasim A Jalil. Faculty of Mechanical Engineering UTM (source: Deitel Associates & Pearson)

Dr M Kasim A Jalil. Faculty of Mechanical Engineering UTM (source: Deitel Associates & Pearson) Lecture 9 Functions Dr M Kasim A Jalil Faculty of Mechanical Engineering UTM (source: Deitel Associates & Pearson) Objectives In this chapter, you will learn: To understand how to construct programs modularly

More information

Chapter 5 C Functions

Chapter 5 C Functions Chapter 5 C Functions Objectives of this chapter: To construct programs from small pieces called functions. Common math functions in math.h the C Standard Library. sin( ), cos( ), tan( ), atan( ), sqrt(

More information

Functions. Angela Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan.

Functions. Angela Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan. Functions Angela Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2009 Fall Outline 5.1 Introduction 5.3 Math Library Functions 5.4 Functions 5.5

More information

Functions in C++ Problem-Solving Procedure With Modular Design C ++ Function Definition: a single

Functions in C++ Problem-Solving Procedure With Modular Design C ++ Function Definition: a single Functions in C++ Problem-Solving Procedure With Modular Design: Program development steps: Analyze the problem Develop a solution Code the solution Test/Debug the program C ++ Function Definition: A module

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

Tutorial 12 Craps Game Application: Introducing Random Number Generation and Enumerations

Tutorial 12 Craps Game Application: Introducing Random Number Generation and Enumerations Tutorial 12 Craps Game Application: Introducing Random Number Generation and Enumerations Outline 12.1 Test-Driving the Craps Game Application 12.2 Random Number Generation 12.3 Using an enum in the Craps

More information

CSE123. Program Design and Modular Programming Functions 1-1

CSE123. Program Design and Modular Programming Functions 1-1 CSE123 Program Design and Modular Programming Functions 1-1 5.1 Introduction A function in C is a small sub-program performs a particular task, supports the concept of modular programming design techniques.

More information

Using pointers with functions

Using pointers with functions Using pointers with functions Recall that our basic use of functions so fare provides for several possibilities. A function can 1. take one or more individual variables as inputs and return a single variable

More information

Two Dimensional Array - An array with a multiple indexs.

Two Dimensional Array - An array with a multiple indexs. LAB5 : Arrays Objectives: 1. To learn how to use C array as a counter. 2. To learn how to add an element to the array. 3. To learn how to delete an element from the array. 4. To learn how to declare two

More information

Functions in C C Programming and Software Tools. N.C. State Department of Computer Science

Functions in C C Programming and Software Tools. N.C. State Department of Computer Science Functions in C C Programming and Software Tools N.C. State Department of Computer Science Functions in C Functions are also called subroutines or procedures One part of a program calls (or invokes the

More information

Project 4: Implementing Malloc Introduction & Problem statement

Project 4: Implementing Malloc Introduction & Problem statement Project 4 (75 points) Assigned: February 14, 2014 Due: March 4, 2014, 11:59 PM CS-3013, Operating Systems C-Term 2014 Project 4: Implementing Malloc Introduction & Problem statement As C programmers, we

More information

Functions. Functions are everywhere in C. Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

Functions. Functions are everywhere in C. Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR 1 Functions Functions are everywhere in C Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR Introduction Function A self-contained program segment that carries

More information

ECE15: Lab #4. Problem 1. University of California San Diego

ECE15: Lab #4. Problem 1. University of California San Diego University of California San Diego ECE15: Lab #4 This lab is a cumulative wrap-up assignment for the entire course. As such, it relates to the material covered in Lecture Units 1 5 and 7 9 in class. Here

More information

Laboratory Assignment #3 Eclipse CDT

Laboratory Assignment #3 Eclipse CDT Lab 3 September 12, 2010 CS-2303, System Programming Concepts, A-term 2012 Objective Laboratory Assignment #3 Eclipse CDT Due: at 11:59 pm on the day of your lab session To learn to learn to use the Eclipse

More information

CS 150 Lab 10 Functions and Random Numbers

CS 150 Lab 10 Functions and Random Numbers CS 150 Lab 10 Functions and Random Numbers The objective of today s lab is to implement functions and random numbers in a simple game. Be sure your output looks exactly like the specified output. Be sure

More information

ECE15: Lab #3. Problem 1. University of California San Diego ( 1) + x4. + x8 + (1)

ECE15: Lab #3. Problem 1. University of California San Diego ( 1) + x4. + x8 + (1) University of California San Diego ECE15: Lab #3 This lab relates specifically to the material covered in Lecture Units 6 and 7 in class, although it assumes knowledge of the previous Lecture Units as

More information

C++ PROGRAMMING SKILLS Part 4: Arrays

C++ PROGRAMMING SKILLS Part 4: Arrays C++ PROGRAMMING SKILLS Part 4: Arrays Outline Introduction to Arrays Declaring and Initializing Arrays Examples Using Arrays Sorting Arrays: Bubble Sort Passing Arrays to Functions Computing Mean, Median

More information

Functions and Recursion

Functions and Recursion Functions and Recursion 1 Outline Introduction Program Components in C++ Math Library Functions Functions Function Definitions Function Prototypes Header Files Random Number Generation Example: A Game

More information

CS 241 Data Organization. August 21, 2018

CS 241 Data Organization. August 21, 2018 CS 241 Data Organization August 21, 2018 Contact Info Instructor: Dr. Marie Vasek Contact: Private message me on the course Piazza page. Office: Room 2120 of Farris Web site: www.cs.unm.edu/~vasek/cs241/

More information

Laboratory Assignment #4 Debugging in Eclipse CDT 1

Laboratory Assignment #4 Debugging in Eclipse CDT 1 Lab 4 (10 points) November 20, 2013 CS-2301, System Programming for Non-majors, B-term 2013 Objective Laboratory Assignment #4 Debugging in Eclipse CDT 1 Due: at 11:59 pm on the day of your lab session

More information

Arrays and Pointers in C & C++

Arrays and Pointers in C & C++ Arrays and Pointers in C & C++ Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2 nd edition, by Kernighan and Ritchie, Absolute C++,

More information

Objectivities. Experiment 1. Lab6 Array I. Description of the Problem. Problem-Solving Tips

Objectivities. Experiment 1. Lab6 Array I. Description of the Problem. Problem-Solving Tips Lab6 Array I Objectivities 1. Using rand to generate random numbers and using srand to seed the random-number generator. 2. Declaring, initializing and referencing arrays. 3. The follow-up questions and

More information

Two Dimensional Array - An array with a multiple indexs.

Two Dimensional Array - An array with a multiple indexs. LAB5 : Arrays Objectives: 1. To learn how to use C array as a counter. 2. To learn how to add an element to the array. 3. To learn how to delete an element from the array. 4. To learn how to declare two

More information

C Arrays. Group of consecutive memory locations Same name and type. Array name + position number. Array elements are like normal variables

C Arrays. Group of consecutive memory locations Same name and type. Array name + position number. Array elements are like normal variables 1 6 C Arrays 6.2 Arrays 2 Array Group of consecutive memory locations Same name and type To refer to an element, specify Array name + position number arrayname[ position number ] First element at position

More information

C: How to Program. Week /Apr/23

C: How to Program. Week /Apr/23 C: How to Program Week 9 2007/Apr/23 1 Review of Chapters 1~5 Chapter 1: Basic Concepts on Computer and Programming Chapter 2: printf and scanf (Relational Operators) keywords Chapter 3: if (if else )

More information

Functions in C C Programming and Software Tools

Functions in C C Programming and Software Tools Functions in C C Programming and Software Tools N.C. State Department of Computer Science Functions in C Functions are also called subroutines or procedures One part of a program calls (or invokes the

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

JTSK Programming in C II C-Lab II. Lecture 3 & 4

JTSK Programming in C II C-Lab II. Lecture 3 & 4 JTSK-320112 Programming in C II C-Lab II Lecture 3 & 4 Xu (Owen) He Spring 2018 Slides modified from Dr. Kinga Lipskoch Planned Syllabus The C Preprocessor Bit Operations Pointers and Arrays (Dynamically

More information

Introduction to Computer Science Midterm 3 Fall, Points

Introduction to Computer Science Midterm 3 Fall, Points Introduction to Computer Science Fall, 2001 100 Points Notes 1. Tear off this sheet and use it to keep your answers covered at all times. 2. Turn the exam over and write your name next to the staple. Do

More information

Chapter 6. Arrays. Copyright 2007 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved.

Chapter 6. Arrays. Copyright 2007 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 6 Arrays Copyright 2007 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 2 Chapter 6 - Arrays 6.1 Introduction 6.2 Arrays 6.3 Declaring Arrays 6.4 Examples Using Arrays

More information

Functions. Prof. Indranil Sen Gupta. Dept. of Computer Science & Engg. Indian Institute t of Technology Kharagpur. Introduction

Functions. Prof. Indranil Sen Gupta. Dept. of Computer Science & Engg. Indian Institute t of Technology Kharagpur. Introduction Functions Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. Indian Institute t of Technology Kharagpur Programming and Data Structure 1 Function Introduction A self-contained program segment that

More information

EECE.2160: ECE Application Programming

EECE.2160: ECE Application Programming Fall 2017 Programming Assignment #10: Doubly-Linked Lists Due Monday, 12/18/17, 11:59:59 PM (Extra credit ( 5 pts on final average), no late submissions or resubmissions) 1. Introduction This assignment

More information

CS : Programming for Non-majors, Fall 2018 Programming Project #2: Census Due by 10:20am Wednesday September

CS : Programming for Non-majors, Fall 2018 Programming Project #2: Census Due by 10:20am Wednesday September CS 1313 010: Programming for Non-majors, Fall 2018 Programming Project #2: Census Due by 10:20am Wednesday September 19 2018 This second assignment will introduce you to designing, developing, testing

More information

C Arrays Pearson Education, Inc. All rights reserved.

C Arrays Pearson Education, Inc. All rights reserved. 1 6 C Arrays 2 Now go, write it before them in a table, and note it in a book. Isaiah 30:8 To go beyond is as wrong as to fall short. Confucius Begin at the beginning, and go on till you come to the end:

More information

Programming Standards: You must conform to good programming/documentation standards. Some specifics:

Programming Standards: You must conform to good programming/documentation standards. Some specifics: CS3114 (Spring 2011) PROGRAMMING ASSIGNMENT #3 Due Thursday, April 7 @ 11:00 PM for 100 points Early bonus date: Wednesday, April 6 @ 11:00 PM for a 10 point bonus Initial Schedule due Thursday, March

More information

Strings(2) CS 201 String. String Constants. Characters. Strings(1) Initializing and Declaring String. Debzani Deb

Strings(2) CS 201 String. String Constants. Characters. Strings(1) Initializing and Declaring String. Debzani Deb CS 201 String Debzani Deb Strings(2) Two interpretations of String Arrays whose elements are characters. Pointer pointing to characters. Strings are always terminated with a NULL characters( \0 ). C needs

More information

Assignment #3 Answers

Assignment #3 Answers Assignment #3 Answers Introductory C Programming UW Experimental College Assignment #3 ANSWERS Question 1. How many elements does the array int a[5] contain? Which is the first element? The last? The array

More information

Review Chapter 6 in Bravaco. Short Answers 1. This type of method does not return a value. a. null b. void c. empty d. anonymous

Review Chapter 6 in Bravaco. Short Answers 1. This type of method does not return a value. a. null b. void c. empty d. anonymous Assignment 3 Methods Review CSC 123 Fall 2018 Notes: All homework must be submitted via e-mail. All parts of assignment must be submitted in a single e-mail with multiple attachments when required. Notes:

More information

LAB: WHILE LOOPS IN C++

LAB: WHILE LOOPS IN C++ LAB: WHILE LOOPS IN C++ MODULE 2 JEFFREY A. STONE and TRICIA K. CLARK COPYRIGHT 2014 VERSION 4.0 PALMS MODULE 2 LAB: WHILE LOOPS IN C++ 2 Introduction This lab will provide students with an introduction

More information

Programming for Engineers Functions

Programming for Engineers Functions Programming for Engineers Functions ICEN 200 Spring 2018 Prof. Dola Saha 1 Introduction Real world problems are larger, more complex Top down approach Modularize divide and control Easier to track smaller

More information

Chapter 6 - Pointers

Chapter 6 - Pointers Chapter 6 - Pointers Outline 1 Introduction 2 Pointer Variable Declarations and Initialization 3 Pointer Operators 4 Calling Functions by Reference 5 Using the const Qualifier with Pointers 6 Bubble Sort

More information

C Tutorial: Part 1. Dr. Charalampos C. Tsimenidis. Newcastle University School of Electrical and Electronic Engineering.

C Tutorial: Part 1. Dr. Charalampos C. Tsimenidis. Newcastle University School of Electrical and Electronic Engineering. C Tutorial: Part 1 Dr. Charalampos C. Tsimenidis Newcastle University School of Electrical and Electronic Engineering September 2013 Why C? Small (32 keywords) Stable Existing code base Fast Low-level

More information

AMCAT Automata Coding Sample Questions And Answers

AMCAT Automata Coding Sample Questions And Answers 1) Find the syntax error in the below code without modifying the logic. #include int main() float x = 1.1; switch (x) case 1: printf( Choice is 1 ); default: printf( Invalid choice ); return

More information

SPRING 2017 CSCI 304 LAB1 (Due on Feb-14, 11:59:59pm)

SPRING 2017 CSCI 304 LAB1 (Due on Feb-14, 11:59:59pm) SPRING 2017 CSCI 304 LAB1 (Due on Feb-14, 11:59:59pm) Objectives: Debugger Standard I/O Arithmetic statements IF/Switch structures Looping structures File I/O Strings Pointers Functions Structures Important

More information

Physics 2660: Fundamentals of Scientific Computing. Lecture 7 Instructor: Prof. Chris Neu

Physics 2660: Fundamentals of Scientific Computing. Lecture 7 Instructor: Prof. Chris Neu Physics 2660: Fundamentals of Scientific Computing Lecture 7 Instructor: Prof. Chris Neu (chris.neu@virginia.edu) Reminder HW06 due Thursday 15 March electronically by noon HW grades are starting to appear!

More information

CS 241 Data Organization using C

CS 241 Data Organization using C CS 241 Data Organization using C Fall 2018 Instructor Name: Dr. Marie Vasek Contact: Private message me on the course Piazza page. Office: Farris 2120 Office Hours: Tuesday 2-4pm and Thursday 9:30-11am

More information

C Functions Pearson Education, Inc. All rights reserved.

C Functions Pearson Education, Inc. All rights reserved. 1 5 C Functions 2 Form ever follows function. Louis Henri Sullivan E pluribus unum. (One composed of many.) Virgil O! call back yesterday, bid time return. William Shakespeare Call me Ishmael. Herman Melville

More information

6-1 (Function). (Function) !*+!"#!, Function Description Example. natural logarithm of x (base e) rounds x to smallest integer not less than x

6-1 (Function). (Function) !*+!#!, Function Description Example. natural logarithm of x (base e) rounds x to smallest integer not less than x (Function) -1.1 Math Library Function!"#! $%&!'(#) preprocessor directive #include !*+!"#!, Function Description Example sqrt(x) square root of x sqrt(900.0) is 30.0 sqrt(9.0) is 3.0 exp(x) log(x)

More information

Programming Assignment IV Due Thursday, June 1, 2017 at 11:59pm

Programming Assignment IV Due Thursday, June 1, 2017 at 11:59pm Programming Assignment IV Due Thursday, June 1, 2017 at 11:59pm 1 Introduction In this assignment, you will implement a code generator for Cool. When successfully completed, you will have a fully functional

More information

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 4

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 4 BIL 104E Introduction to Scientific and Engineering Computing Lecture 4 Introduction Divide and Conquer Construct a program from smaller pieces or components These smaller pieces are called modules Functions

More information

1. Introduction. 2. Deliverables

1. Introduction. 2. Deliverables 16.216: ECE Application Programming Summer 2014 Programming Assignment #10: Doubly-Linked Lists Due Friday, 6/27/14, 12:00 PM (noon) NO LATE ASSIGNMENTS 1. Introduction This assignment deals with the combination

More information

Programming Tips for CS758/858

Programming Tips for CS758/858 Programming Tips for CS758/858 January 28, 2016 1 Introduction The programming assignments for CS758/858 will all be done in C. If you are not very familiar with the C programming language we recommend

More information

Lab Exam 1 D [1 mark] Give an example of a sample input which would make the function

Lab Exam 1 D [1 mark] Give an example of a sample input which would make the function CMPT 127 Spring 2019 Grade: / 20 First name: Last name: Student Number: Lab Exam 1 D400 1. [1 mark] Give an example of a sample input which would make the function scanf( "%f", &f ) return -1? Answer:

More information

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University Fundamental Data Types CSE 130: Introduction to Programming in C Stony Brook University Program Organization in C The C System C consists of several parts: The C language The preprocessor The compiler

More information

CpSc 1111 Lab 9 2-D Arrays

CpSc 1111 Lab 9 2-D Arrays CpSc 1111 Lab 9 2-D Arrays Overview This week, you will gain some experience with 2-dimensional arrays, using loops to do the following: initialize a 2-D array with data from an input file print out the

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

Project Data: Manipulating Bits

Project Data: Manipulating Bits CSCI0330 Intro Computer Systems Doeppner Project Data: Manipulating Bits Due: September 26, 2018 at 11:59pm 1 Introduction 1 2 Assignment 1 2.1 Collaboration 3 2.2 TA Hours 3 3 The Puzzles 3 3.1 Bit Manipulations

More information

Programming Assignment 2

Programming Assignment 2 CS 122 Fall, 2004 Programming Assignment 2 New Mexico Tech Department of Computer Science Programming Assignment 2 CS122 Algorithms and Data Structures Due 11:00AM, Wednesday, October 13th, 2004 Objectives:

More information

Physics 2660: Fundamentals of Scientific Computing. Lecture 3 Instructor: Prof. Chris Neu

Physics 2660: Fundamentals of Scientific Computing. Lecture 3 Instructor: Prof. Chris Neu Physics 2660: Fundamentals of Scientific Computing Lecture 3 Instructor: Prof. Chris Neu (chris.neu@virginia.edu) Announcements Weekly readings will be assigned and available through the class wiki home

More information

Computer Science & Engineering 150A Problem Solving Using Computers

Computer Science & Engineering 150A Problem Solving Using Computers Computer Science & Engineering 150A Problem Solving Using Computers Lecture 06 - Stephen Scott Adapted from Christopher M. Bourke 1 / 30 Fall 2009 Chapter 8 8.1 Declaring and 8.2 Array Subscripts 8.3 Using

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

CS201 - Introduction to Programming FAQs By

CS201 - Introduction to Programming FAQs By CS201 - Introduction to Programming FAQs By What are pointers? Answer: A pointer is a variable that represents/stores location of a data item, such as a variable or array element What s the difference

More information

Objectives of This Chapter

Objectives of This Chapter Chapter 6 C Arrays Objectives of This Chapter Array data structures to represent the set of values. Defining and initializing arrays. Defining symbolic constant in a program. Using arrays to store, list,

More information

CS : Programming for Non-majors, Summer 2007 Programming Project #2: Census Due by 12:00pm (noon) Wednesday June

CS : Programming for Non-majors, Summer 2007 Programming Project #2: Census Due by 12:00pm (noon) Wednesday June CS 1313 010: Programming for Non-majors, Summer 2007 Programming Project #2: Census Due by 12:00pm (noon) Wednesday June 20 2007 This second assignment will introduce you to designing, developing, testing

More information

Course Information and Introduction

Course Information and Introduction August 22, 2017 Course Information 1 Instructors : Email : arash.rafiey@indstate.edu Office : Root Hall A-127 Office Hours : Tuesdays 11:30 pm 12:30 pm. Root Hall, A127. 2 Course Home Page : http://cs.indstate.edu/~arash/cs256.html

More information

C Functions. CS 2060 Week 4. Prof. Jonathan Ventura

C Functions. CS 2060 Week 4. Prof. Jonathan Ventura CS 2060 Week 4 1 Modularizing Programs Modularizing programs in C Writing custom functions Header files 2 Function Call Stack The function call stack Stack frames 3 Pass-by-value Pass-by-value and pass-by-reference

More information

CS : Programming for Non-Majors, Fall 2018 Programming Project #5: Big Statistics Due by 10:20am Wednesday November

CS : Programming for Non-Majors, Fall 2018 Programming Project #5: Big Statistics Due by 10:20am Wednesday November CS 1313 010: Programming for Non-Majors, Fall 2018 Programming Project #5: Big Statistics Due by 10:20am Wednesday November 7 2018 This fifth programming project will give you experience writing programs

More information

Assignment Checklist. Prelab Activities. Lab Exercises. Labs Provided by Instructor. Postlab Activities. Section:

Assignment Checklist. Prelab Activities. Lab Exercises. Labs Provided by Instructor. Postlab Activities. Section: 7 Arrays Now go, write it before them in a table, and note it in a book. Isaiah 30:8 To go beyond is as wrong as to fall short. Confucius Begin at the beginning, and go on till you come to the end: then

More information

C Programs: Simple Statements and Expressions

C Programs: Simple Statements and Expressions .. Cal Poly CPE 101: Fundamentals of Computer Science I Alexander Dekhtyar.. C Programs: Simple Statements and Expressions C Program Structure A C program that consists of only one function has the following

More information

CSE 351, Spring 2010 Lab 7: Writing a Dynamic Storage Allocator Due: Thursday May 27, 11:59PM

CSE 351, Spring 2010 Lab 7: Writing a Dynamic Storage Allocator Due: Thursday May 27, 11:59PM CSE 351, Spring 2010 Lab 7: Writing a Dynamic Storage Allocator Due: Thursday May 27, 11:59PM 1 Instructions In this lab you will be writing a dynamic storage allocator for C programs, i.e., your own version

More information

COMP 110 Programming Exercise: Simulation of the Game of Craps

COMP 110 Programming Exercise: Simulation of the Game of Craps COMP 110 Programming Exercise: Simulation of the Game of Craps Craps is a game of chance played by rolling two dice for a series of rolls and placing bets on the outcomes. The background on probability,

More information

Project #1: Tracing, System Calls, and Processes

Project #1: Tracing, System Calls, and Processes Project #1: Tracing, System Calls, and Processes Objectives In this project, you will learn about system calls, process control and several different techniques for tracing and instrumenting process behaviors.

More information

Agenda. Peer Instruction Question 1. Peer Instruction Answer 1. Peer Instruction Question 2 6/22/2011

Agenda. Peer Instruction Question 1. Peer Instruction Answer 1. Peer Instruction Question 2 6/22/2011 CS 61C: Great Ideas in Computer Architecture (Machine Structures) Introduction to C (Part II) Instructors: Randy H. Katz David A. Patterson http://inst.eecs.berkeley.edu/~cs61c/sp11 Spring 2011 -- Lecture

More information

CS 361 Computer Systems Fall 2017 Homework Assignment 1 Linking - From Source Code to Executable Binary

CS 361 Computer Systems Fall 2017 Homework Assignment 1 Linking - From Source Code to Executable Binary CS 361 Computer Systems Fall 2017 Homework Assignment 1 Linking - From Source Code to Executable Binary Due: Thursday 14 Sept. Electronic copy due at 9:00 A.M., optional paper copy may be delivered to

More information

PRINCIPLES OF OPERATING SYSTEMS

PRINCIPLES OF OPERATING SYSTEMS PRINCIPLES OF OPERATING SYSTEMS Tutorial-1&2: C Review CPSC 457, Spring 2015 May 20-21, 2015 Department of Computer Science, University of Calgary Connecting to your VM Open a terminal (in your linux machine)

More information

Programming Assignment Multi-Threading and Debugging 2

Programming Assignment Multi-Threading and Debugging 2 Programming Assignment Multi-Threading and Debugging 2 Due Date: Friday, June 1 @ 11:59 pm PAMT2 Assignment Overview The purpose of this mini-assignment is to continue your introduction to parallel programming

More information

Chapter 4 Functions By C.K. Liang

Chapter 4 Functions By C.K. Liang 1 Chapter 4 Functions By C.K. Liang What you should learn? 2 To construct programs modularly from small pieces called functions Math functions in C standard library Create new functions Pass information

More information

Computer Science & Engineering 150A Problem Solving Using Computers

Computer Science & Engineering 150A Problem Solving Using Computers Computer Science & Engineering 150A Problem Solving Using Computers Lecture 03 - Stephen Scott (Adapted from Christopher M. Bourke) 1 / 41 Fall 2009 Chapter 3 3.1 Building Programs from Existing Information

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

Lab Instructor : Jean Lai

Lab Instructor : Jean Lai Lab Instructor : Jean Lai Group related statements to perform a specific task. Structure the program (No duplicate codes!) Must be declared before used. Can be invoked (called) as any number of times.

More information

Welcome to... CS113: Introduction to C

Welcome to... CS113: Introduction to C Welcome to... CS113: Introduction to C Instructor: Erik Sherwood E-mail: wes28@cs.cornell.edu Course Website: http://www.cs.cornell.edu/courses/cs113/2005fa/ The website is linked to from the courses page

More information

Programming assignment A

Programming assignment A Programming assignment A ASCII Minesweeper Official release on Feb 14 th at 1pm (Document may change before then without notice) Due 5pm Feb 25 th Minesweeper is computer game that was first written in

More information

Computer Science & Engineering 150A Problem Solving Using Computers. Chapter 3. Existing Information. Notes. Notes. Notes. Lecture 03 - Functions

Computer Science & Engineering 150A Problem Solving Using Computers. Chapter 3. Existing Information. Notes. Notes. Notes. Lecture 03 - Functions Computer Science & Engineering 150A Problem Solving Using Computers Lecture 03 - Functions Stephen Scott (Adapted from Christopher M. Bourke) Fall 2009 1 / 1 cbourke@cse.unl.edu Chapter 3 3.1 Building

More information

ENCE 3241 Data Lab. 60 points Due February 19, 2010, by 11:59 PM

ENCE 3241 Data Lab. 60 points Due February 19, 2010, by 11:59 PM 0 Introduction ENCE 3241 Data Lab 60 points Due February 19, 2010, by 11:59 PM The purpose of this assignment is for you to become more familiar with bit-level representations and manipulations. You ll

More information

CMSC 201 Fall 2016 Homework 6 Functions

CMSC 201 Fall 2016 Homework 6 Functions CMSC 201 Fall 2016 Homework 6 Functions Assignment: Homework 6 Functions Due Date: Wednesday, October 26th, 2016 by 8:59:59 PM Value: 40 points Collaboration: For Homework 6, collaboration is not allowed

More information

CS1110 Lab 6 (Mar 17-18, 2015)

CS1110 Lab 6 (Mar 17-18, 2015) CS1110 Lab 6 (Mar 17-18, 2015) First Name: Last Name: NetID: The lab assignments are very important and you must have a CS 1110 course consultant tell CMS that you did the work. (Correctness does not matter.)

More information

Project 2: Buffer Manager

Project 2: Buffer Manager Project 2: Buffer Manager Due on 10/25/17 INTRODUCTION The goal of the BadgerDB projects is to allow students in CS 564 to learn about the internals of a data processing engine. In this assignment, you

More information

ECET 264 C Programming Language with Applications

ECET 264 C Programming Language with Applications ECET 264 C Programming Language with Applications Lecture 10 C Standard Library Functions Paul I. Lin Professor of Electrical & Computer Engineering Technology http://www.etcs.ipfw.edu/~lin Lecture 10

More information

CS 470 Operating Systems Spring 2013 Shell Project

CS 470 Operating Systems Spring 2013 Shell Project CS 470 Operating Systems Spring 2013 Shell Project 40 points Out: January 11, 2013 Due: January 25, 2012 (Friday) The purpose of this project is provide experience with process manipulation and signal

More information

CSC101 - BMCC - Spring /22/2019. Lab 07

CSC101 - BMCC - Spring /22/2019. Lab 07 CSC101 - BMCC - Spring 2019 03/22/2019 Lab 07 Download and extract the content of CSC101_Lab07.zip from the course web page (labs.html); then browse and open the folder Lab07 where you will find all necessary

More information

Project 5 Handling Bit Arrays and Pointers in C

Project 5 Handling Bit Arrays and Pointers in C CS 255 Project 5 Handling Bit Arrays and Pointers in C Due: Thursday, Apr. 30 by 8:00am. No late submissions! Assignment: This homework is adapted from the CS450 Assignment #1 that Prof. Mandelberg uses

More information

Calling Prewritten Functions in C

Calling Prewritten Functions in C Calling Prewritten Functions in C We've already called two prewritten functions that are found in the C library stdio.h: printf, scanf. The function specifications for these two are complicated (they allow

More information

CME 112- Programming Languages II. Week 1 Introduction, Scope Rules and Generating Random Numbers

CME 112- Programming Languages II. Week 1 Introduction, Scope Rules and Generating Random Numbers 1 CME 112- Programming Languages II Week 1 Introduction, Scope Rules and Generating Random Numbers Assist. Prof. Dr. Caner Özcan You have two options at any given moment. You can either: Step forward into

More information