ECE15: Homework 10. void wordstats(file *fp, char string[]) { void printfrequencies(file *fp) {

Size: px
Start display at page:

Download "ECE15: Homework 10. void wordstats(file *fp, char string[]) { void printfrequencies(file *fp) {"

Transcription

1 ECE15: Homework 10 Recall that in the Unix dialogues shown below, we denote the prompt by ( )$ and show user input in red and computer output in black. We indicate a single space by in computer output, and by in user input. You can assume that the user will enter valid inputs. For this homework you will need to create two additional files: myheader.h containing the declarations of the functions you will use for all three homework problems, and myfunctions.c containing the definitions of the functions you will use for all three problems. Each of your three programs will start with #include "myheader.h" and will contain only main and no other function. Each program (say xyz.c) will have to be compiled as gcc xyz.c myfunctions.c. To get you started, here is the myheader.h file you need to use, and a skeleton of the myfunctions.c file you need to write. To copy them to your directory, type cp -r /../public/hw8/ / (The myheader.h file in public also includes a definition of M PI in case you don t have it.) // This is your myheader.h file, you can cut and paste (or copy) it. // Declarations for sortfile.c void sort(int array[], int length); // Declarations for statistics.c void lowercasestring(char string[]); void wordstats(file *fp, char string[]); void printfrequencies(file *fp); // Declarations for car-pol.c void car2pol(double x, double y, double *pr, double *ptheta); void pol2car(double r, double theta, double *px, double *py); // This is a skeleton for your myfunctions.c file // Functions for sortfile.c void sort(int array[], int length) { enter body } // Functions for statistics.c int letterfrequencies[26]; // Global array for wordstats, printfrequencies void lowercasestring(char string[]) { enter body } void wordstats(file *fp, char string[]) { enter body, use letterfrequencies[], use a static variable } void printfrequencies(file *fp) { enter body, use letterfrequencies[] } // Functions for car-pol.c void car2pol(double x, double y, double *pr, double *ptheta) { enter body } void pol2car(double r, double theta, double *px, double *py) { enter body }

2 Problem 1. Write a program sortfile.c that takes as command line arguments an input file name, an output file name, and an optional third argument indicating the largest number of integers to sort. The program opens the input file consisting of at most 50 integers, sorts them in increasing order, and prints the sorted sequence to the output file. If the optional argument exists, let s call it k, then if k is smaller than the number of integers in the input file, only the first k integers in the input file will be sorted and printed to the output file. You can assume that the input file exists and has the right format. ( )$ more input ( )$ a.out input1 output1.1 ( )$ more output ( )$ a.out input1 output1.2 5 ( )$ more output ( )$ more input ( )$ a.out input2 output2.1 ( )$ more output ( )$ a.out input2 output ( )$ more output ( )$ a.out input2 output2.3 0 ( )$ more output2.3 ( )$ more input3 ( )$ a.out input3 output3 ( )$ more output3 ( )$ The program must call the following functions that you will define in myfunctions.c. void sort(int array[], int length) sorts the first length elements of array in increasing order. For example, if array is { } and length is 3, then sort will modify array to { }. You can assume that length will be at most the size of array. The file sortfile.c will consist of only just main defined and functioning as follows. int main(int argc, char *argv[]) opens input file argv[1], calls sort to sort its elements, and prints the sorted elements in the output file argv[2]. If argv[3] exists, then it is a an integer k. If k is smaller than the number of elements in the input file, then only the first k elements will be sorted and printed in the output file. 2

3 Problem 2. This program provides practice with global and static variables. In real-life programming you may choose to define these variables differently. Write a program statistics.c that takes as command-line arguments a sequence of words, and then asks the user for the name of an output file. The program prints in the file the lowercase form of each word, its length, and the cumulative length so far. After doing that for all words, the program prints each letter of the alphabet that was included in these words followed by the number of times the letter appeared. You may assume that the user will type only letters (no punctuations or numbers). ( )$ a.out Peter Piper picked a peck Output file: output1 ( )$ more output1 peter: length=5 total=5 piper: length=5 total=10 picked: length=6 total=16 a: length=1 total=17 peck: length=4 total=21 Letters: a:1 c:2 d:1 e:5 i:2 k:2 p:5 r:2 t:1 ( )$ a.out abracadabra Output file: output2 ( )$ more output2 abracadabra: length=11 total=11 Letters: a:5 b:2 c:1 d:1 r:2 ( )$ a.out Output file: output3 ( )$ more output3 Letters: ( )$ The program should use the following variables: int letterfrequencies[26] a global array that tracks the number of times each letter has appeared so far. It will be used by the functions wordstats and printfrequencies. This variable is already defined for you in myfunctions.c static int cumulativelength a static variable defined inside the function wordstats that tracks the cumulative length of words so far. The program should include the following functions. Of these functions, main should be defined in statistics.c and all other functions should be defined in myfunctions.c void lowercasestring(char string[]) Converts all upper-case letters in string to lower case. You can use the same-named function you wrote for the previous homework. void wordstats(file *fp, char string[]) Prints everything below to the file pointed to by fp. Prints string. 3

4 Prints the length of string. You can determine the length by using the function stringlen you wrote for the last homework or the function strlen defined in string.h. Updates and prints the static variable cumulativelength (see above) that tracks the cumulative word lengths so far. Updates a global array letterfrequencies (see above) that tracks the number of times each letter has appeared among the words processed so far. void printfrequencies(file *fp) Prints everything below to the output file pointed to by fp. Checks the global array letterfrequencies, and for each letter from a to z that appeared at least once, prints the number of times it appeared. int main(int argc, char *argv[]) Asks the user for the name of an output file, and opens the file. For each word in the command line, calls lowercasestring to convert uppercase letter to lower, and then wordstats to print the word and cumulative lengths in the file, and to update the number of times each letter appears. After all words are processed, calls printfrequencies to print the number of time each seen letter has appeared. 4

5 Problem 3. A 2-dimensional vector can be represented by its Cartesian coordinates (x, y) indicating its projections on the horizontal and vertical axes respectively, or by its polar coordinates (r, θ) indicating its distance from the origin and its angle from the horizontal axis respectively. See for example the following figure π 6 π (x,y) = ( 3,1) (r,θ) = (2, 5π 6 ) (x,y) = (1,1) (r,θ) = ( 2, π 4 ) Figure 1: Two vectors and their Cartesian and polar representations As is well known, polar coordinates can be converted to Cartesian via the transform x = r cosθ and y = r sinθ, and Cartesian coordinates can be converted to polar via the transform arctan(y/x) if x > 0, r = arctan(y/x) + π if x < 0, x 2 + y 2 and θ = π/2 if x = 0, y > 0, π/2 if x = 0, y < 0, 0 if x = 0, y = 0. Note that θ is expressed in radians, that the last three cases are provided to avoid division by 0, and that for (x,y) = (0,0) the angle θ does not matter, but we define it to be 0, and please do so too. Write a program car-pol.c that takes two command-line arguments: an input-file name and an output-file name. The input can be of two types: If it starts with the word Cartesian (so capitalized), then it will be followed by zero or more (x,y) pairs. The program should create an output file of the specified name that starts with the word Polar (so capitalized) and continues with the polar-coordinate equivalent of all original vectors. Conversely, if the input file start with the word Polar, then it will be followed zero or more (r,θ) pairs. The program should create an output file of the specified name that starts with Cartesian and continues with the Cartesian-coordinate equivalent of all original vectors. You can use the math.h functions cos, sin, and atan, but not atan2. In your code, have main read the command-line arguments and read and write the files. Declare the following functions in myheader.h and define them in myfunctions.c Your car-pol.c file should consist of just main and call the following functions that should be defined in myfunctions.c 5

6 void car2pol(double x, double y, double *pr, double *ptheta); converts Cartesian (x,y) to polar (r,θ) where pr and ptheta are pointers to r and θ void pol2car(double r, double theta, double *px, double *py); convert polar (r,θ) to Cartesian (x,y), where px and py are pointers to x and y. Your answers will be considered correct if they are within 0.01% (factor of 1 ± ) from those listed by test.sh. ( )$ more file1 Cartesian ( )$ a.out file1 file2 ( )$ more file2 Polar ( )$ a.out file2 file3 ( )$ more file3 Cartesian e e-05-3 ( )$ more file4 Cartesian ( )$ a.out file4 file5 ( )$ more file5 Polar ( )$ 6

To graph the point (r, θ), simply go out r units along the initial ray, then rotate through the angle θ. The point (1, 5π 6

To graph the point (r, θ), simply go out r units along the initial ray, then rotate through the angle θ. The point (1, 5π 6 Polar Coordinates Any point in the plane can be described by the Cartesian coordinates (x, y), where x and y are measured along the corresponding axes. However, this is not the only way to represent points

More information

To graph the point (r, θ), simply go out r units along the initial ray, then rotate through the angle θ. The point (1, 5π 6. ) is graphed below:

To graph the point (r, θ), simply go out r units along the initial ray, then rotate through the angle θ. The point (1, 5π 6. ) is graphed below: Polar Coordinates Any point in the plane can be described by the Cartesian coordinates (x, y), where x and y are measured along the corresponding axes. However, this is not the only way to represent points

More information

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

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 14 BIL 104E Introduction to Scientific and Engineering Computing Lecture 14 Because each C program starts at its main() function, information is usually passed to the main() function via command-line arguments.

More information

CS261: HOMEWORK 2 Due 04/13/2012, at 2pm

CS261: HOMEWORK 2 Due 04/13/2012, at 2pm CS261: HOMEWORK 2 Due 04/13/2012, at 2pm Submit six *.c files via the TEACH website: https://secure.engr.oregonstate.edu:8000/teach.php?type=want_auth 1. Introduction The purpose of HW2 is to help you

More information

MATHEMATICS FOR ENGINEERING TUTORIAL 5 COORDINATE SYSTEMS

MATHEMATICS FOR ENGINEERING TUTORIAL 5 COORDINATE SYSTEMS MATHEMATICS FOR ENGINEERING TUTORIAL 5 COORDINATE SYSTEMS This tutorial is essential pre-requisite material for anyone studying mechanical engineering. This tutorial uses the principle of learning by example.

More information

Pre-Calc Unit 14: Polar Assignment Sheet April 27 th to May 7 th 2015

Pre-Calc Unit 14: Polar Assignment Sheet April 27 th to May 7 th 2015 Pre-Calc Unit 14: Polar Assignment Sheet April 27 th to May 7 th 2015 Date Objective/ Topic Assignment Did it Monday Polar Discovery Activity pp. 4-5 April 27 th Tuesday April 28 th Converting between

More information

Introduction to MATLAB

Introduction to MATLAB Outlines September 9, 2004 Outlines Part I: Review of Previous Lecture Part II: Part III: Writing MATLAB Functions Review of Previous Lecture Outlines Part I: Review of Previous Lecture Part II: Part III:

More information

Introduction to MATLAB

Introduction to MATLAB Outlines January 30, 2008 Outlines Part I: Part II: Writing MATLAB Functions Starting MATLAB Exiting MATLAB Getting Help Command Window Workspace Command History Current Directory Selector Real Values

More information

CS3157: Advanced Programming. Outline

CS3157: Advanced Programming. Outline CS3157: Advanced Programming Lecture #8 Feb 27 Shlomo Hershkop shlomo@cs.columbia.edu 1 Outline More c Preprocessor Bitwise operations Character handling Math/random Review for midterm Reading: k&r ch

More information

6.1 Polar Coordinates

6.1 Polar Coordinates 6.1 Polar Coordinates Introduction This chapter introduces and explores the polar coordinate system, which is based on a radius and theta. Students will learn how to plot points and basic graphs in this

More information

MATHEMATICS FOR ENGINEERING TRIGONOMETRY

MATHEMATICS FOR ENGINEERING TRIGONOMETRY MATHEMATICS FOR ENGINEERING TRIGONOMETRY TUTORIAL SOME MORE RULES OF TRIGONOMETRY This is the one of a series of basic tutorials in mathematics aimed at beginners or anyone wanting to refresh themselves

More information

Exercise 1.1 Hello world

Exercise 1.1 Hello world Exercise 1.1 Hello world The goal of this exercise is to verify that computer and compiler setup are functioning correctly. To verify that your setup runs fine, compile and run the hello world example

More information

cs3157: another C lecture (mon-21-feb-2005) C pre-processor (3).

cs3157: another C lecture (mon-21-feb-2005) C pre-processor (3). cs3157: another C lecture (mon-21-feb-2005) C pre-processor (1). today: C pre-processor command-line arguments more on data types and operators: booleans in C logical and bitwise operators type conversion

More information

APT Session 4: C. Software Development Team Laurence Tratt. 1 / 14

APT Session 4: C. Software Development Team Laurence Tratt. 1 / 14 APT Session 4: C Laurence Tratt Software Development Team 2017-11-10 1 / 14 http://soft-dev.org/ What to expect from this session 1 C. 2 / 14 http://soft-dev.org/ Prerequisites 1 Install either GCC or

More information

10.1 Curves Defined by Parametric Equations

10.1 Curves Defined by Parametric Equations 10.1 Curves Defined by Parametric Equations Ex: Consider the unit circle from Trigonometry. What is the equation of that circle? There are 2 ways to describe it: x 2 + y 2 = 1 and x = cos θ y = sin θ When

More information

Warm-up sheet: Programming in C

Warm-up sheet: Programming in C Warm-up sheet: Programming in C Programming for Embedded Systems Uppsala University January 20, 2015 Introduction Here are some basic exercises in the programming language C. Hopefully you already have

More information

COMP1917: 09 Arrays and Strings

COMP1917: 09 Arrays and Strings COMP1917: 09 Arrays and Strings Sim Mautner s.mautner@unsw.edu.au August 15, 2016 Sim Mautner (UNSW) COMP1917: 09 Arrays and Strings August 15, 2016 1 / 14 Arrays int sum(int n1, int n2); int sum(int n1,

More information

Pointers. Pointer References

Pointers. Pointer References Pointers Pointers are variables whose values are the addresses of other variables Basic operations address of (reference) indirection (dereference) Suppose x and y are integers, p is a pointer to an integer:

More information

Scheme G. Sample Test Paper-I. Course Name : Computer Engineering Group Course Code : CO/CD/CM/CW/IF Semester : Second Subject Tile : Programming in C

Scheme G. Sample Test Paper-I. Course Name : Computer Engineering Group Course Code : CO/CD/CM/CW/IF Semester : Second Subject Tile : Programming in C Sample Test Paper-I Marks : 25 Time:1 Hrs. Q1. Attempt any THREE 09 Marks a) State four relational operators with meaning. b) State the use of break statement. c) What is constant? Give any two examples.

More information

CGS 3460 Summer 07 Midterm Exam

CGS 3460 Summer 07 Midterm Exam Short Answer 3 Points Each 1. What would the unix command gcc somefile.c -o someotherfile.exe do? 2. Name two basic data types in C. 3. A pointer data type holds what piece of information? 4. This key

More information

Algorithms & Data Structures

Algorithms & Data Structures GATE- 2016-17 Postal Correspondence 1 Algorithms & Data Structures Computer Science & Information Technology (CS) 20 Rank under AIR 100 Postal Correspondence Examination Oriented Theory, Practice Set Key

More information

Pointers. Pointers. Pointers (cont) CS 217

Pointers. Pointers. Pointers (cont) CS 217 Pointers CS 217 Pointers Variables whose values are the addresses of variables Operations address of (reference) & indirection (dereference) * arithmetic +, - Declaration mimics use char *p; *p is a char,

More information

Online Judge and C. Roy Chan. January 12, Outline Information Online Judge Introduction to C. CSC2100B Data Structures Tutorial 1

Online Judge and C. Roy Chan. January 12, Outline Information Online Judge Introduction to C. CSC2100B Data Structures Tutorial 1 Roy Chan CSC2100B Data Structures Tutorial 1 January 12, 2009 1 / 38 1 Information Your TA team Course Information Assignment 2 Online Judge Writing Your Assignment Program Submitting Your Program Online

More information

Worksheet 5. 3 Less trigonometry and more dishonesty/linear algebra knowledge Less trigonometry, less dishonesty... 4

Worksheet 5. 3 Less trigonometry and more dishonesty/linear algebra knowledge Less trigonometry, less dishonesty... 4 Worksheet 5 Contents 1 Just look at the book, on page 74 1 2 Trigonometry and honesty 1 3 Less trigonometry and more dishonesty/linear algebra knowledge 3 3.1 Less trigonometry, less dishonesty...............................

More information

Announcements. Strings and Pointers. Strings. Initializing Strings. Character I/O. Lab 4. Quiz. July 18, Special character arrays

Announcements. Strings and Pointers. Strings. Initializing Strings. Character I/O. Lab 4. Quiz. July 18, Special character arrays Strings and Pointers Announcements Lab 4 Why are you taking this course? Lab 5 #, 8: Reading in data from file using fscanf Quiz Quiz Strings Special character arrays End in null character, \ char hi[6];

More information

Introduction to C Language

Introduction to C Language Introduction to C Language Instructor: Professor I. Charles Ume ME 6405 Introduction to Mechatronics Fall 2006 Instructor: Professor Charles Ume Introduction to C Language History of C Language In 1972,

More information

Fall 2016 Semester METR 3113 Atmospheric Dynamics I: Introduction to Atmospheric Kinematics and Dynamics

Fall 2016 Semester METR 3113 Atmospheric Dynamics I: Introduction to Atmospheric Kinematics and Dynamics Fall 2016 Semester METR 3113 Atmospheric Dynamics I: Introduction to Atmospheric Kinematics and Dynamics Lecture 5 August 31 2016 Topics: Polar coordinate system Conversion of polar coordinates to 2-D

More information

Practical Exercise 1 Question 1: The Hello World Program Write a Fortran 95 program to write out Hello World on the screen.

Practical Exercise 1 Question 1: The Hello World Program Write a Fortran 95 program to write out Hello World on the screen. Practical Exercise Question : The Hello World Program Write a Fortran 95 program to write out Hello World on the screen. Question : Some Division One Results A particular number can be expressed as the

More information

today cs3157-fall2002-sklar-lect05 1

today cs3157-fall2002-sklar-lect05 1 today homework #1 due on monday sep 23, 6am some miscellaneous topics: logical operators random numbers character handling functions FILE I/O strings arrays pointers cs3157-fall2002-sklar-lect05 1 logical

More information

Math 231E, Lecture 34. Polar Coordinates and Polar Parametric Equations

Math 231E, Lecture 34. Polar Coordinates and Polar Parametric Equations Math 231E, Lecture 34. Polar Coordinates and Polar Parametric Equations 1 Definition of polar coordinates Let us first recall the definition of Cartesian coordinates: to each point in the plane we can

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

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

Presented, and Compiled, By. Bryan Grant. Jessie Ross

Presented, and Compiled, By. Bryan Grant. Jessie Ross P a g e 1 Presented, and Compiled, By Bryan Grant Jessie Ross August 3 rd, 2016 P a g e 2 Day 1 Discovering Polar Graphs Days 1 & 2 Adapted from Nancy Stephenson - Clements High School, Sugar Land, Texas

More information

Overview (1A) Young Won Lim 9/25/17

Overview (1A) Young Won Lim 9/25/17 Overview (1A) Copyright (c) 2009-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later

More information

Programming and Data Structure

Programming and Data Structure Programming and Data Structure Sujoy Ghose Sudeshna Sarkar Jayanta Mukhopadhyay Dept. of Computer Science & Engineering. Indian Institute of Technology Kharagpur Spring Semester 2012 Programming and Data

More information

Basic C Programming. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

Basic C Programming. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island Basic C Programming Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island Announcements Exam 1 (20%): Feb. 27 (Tuesday) Tentative Proposal Deadline:

More information

Indian Institute of Technology Kharagpur Programming and Data Structures (CS10001) Autumn : End-Semester Examination

Indian Institute of Technology Kharagpur Programming and Data Structures (CS10001) Autumn : End-Semester Examination Indian Institute of Technology Kharagpur Programming and Data Structures (CS10001) Autumn 2017-18: End-Semester Examination Time: 3 Hours Full Marks: 100 INSTRUCTIONS 1. Answer ALL questions. 2. Please

More information

Math 144 Activity #4 Connecting the unit circle to the graphs of the trig functions

Math 144 Activity #4 Connecting the unit circle to the graphs of the trig functions 144 p 1 Math 144 Activity #4 Connecting the unit circle to the graphs of the trig functions Graphing the sine function We are going to begin this activity with graphing the sine function ( y = sin x).

More information

Question 2. [5 points] Given the following symbolic constant definition

Question 2. [5 points] Given the following symbolic constant definition CS 101, Spring 2012 Mar 20th Exam 2 Name: Question 1. [5 points] Determine which of the following function calls are valid for a function with the prototype: void drawrect(int width, int height); Assume

More information

C-String Library Functions

C-String Library Functions Strings Class 34 C-String Library Functions there are several useful functions in the cstring library strlen: the number of characters before the \0 strncat: concatenate two strings together strncpy: overwrite

More information

6.3 Converting Between Systems

6.3 Converting Between Systems www.ck1.org Chapter 6. The Polar System 6. Converting Between Systems Learning Objectives Convert rectangular coordinates to polar coordinates. Convert equations given in rectangular form to equations

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

Common Misunderstandings from Exam 1 Material

Common Misunderstandings from Exam 1 Material Common Misunderstandings from Exam 1 Material Kyle Dewey Stack and Heap Allocation with Pointers char c = c ; char* p1 = malloc(sizeof(char)); char** p2 = &p1; Where is c allocated? Where is p1 itself

More information

Programming in C. 3. Pointers and Structures. Dr. Neel Krishnaswami University of Cambridge

Programming in C. 3. Pointers and Structures. Dr. Neel Krishnaswami University of Cambridge Programming in C 3. Pointers and Structures Dr. Neel Krishnaswami University of Cambridge (based on notes from and with thanks to Anil Madhavapeddy, Alan Mycroft, Alastair Beresford and Andrew Moore) Michaelmas

More information

BSM540 Basics of C Language

BSM540 Basics of C Language BSM540 Basics of C Language Chapter 4: Character strings & formatted I/O Prof. Manar Mohaisen Department of EEC Engineering Review of the Precedent Lecture To explain the input/output functions printf()

More information

ELEC 377 C Programming Tutorial. ELEC Operating Systems

ELEC 377 C Programming Tutorial. ELEC Operating Systems ELE 377 Programming Tutorial Outline! Short Introduction! History & Memory Model of! ommon Errors I have seen over the years! Work through a linked list example on the board! - uses everything I talk about

More information

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary GATE- 2016-17 Postal Correspondence 1 C-Programming Computer Science & Information Technology (CS) 20 Rank under AIR 100 Postal Correspondence Examination Oriented Theory, Practice Set Key concepts, Analysis

More information

SU2017. LAB 1 (May 4/9) Introduction to C, Function Declaration vs. Definition, Basic I/O (scanf/printf, getchar/putchar)

SU2017. LAB 1 (May 4/9) Introduction to C, Function Declaration vs. Definition, Basic I/O (scanf/printf, getchar/putchar) SU2017. LAB 1 (May 4/9) Introduction to C, Function Declaration vs. Definition, Basic I/O (scanf/printf, getchar/putchar) 1 Problem A 1.1 Specification Write an ANSI-C program that reads input from the

More information

mith College Computer Science CSC352 Week #7 Spring 2017 Introduction to C Dominique Thiébaut

mith College Computer Science CSC352 Week #7 Spring 2017 Introduction to C Dominique Thiébaut mith College CSC352 Week #7 Spring 2017 Introduction to C Dominique Thiébaut dthiebaut@smith.edu Learning C in 2 Hours D. Thiebaut Dennis Ritchie 1969 to 1973 AT&T Bell Labs Close to Assembly Unix Standard

More information

Arrays and Pointers in C. Alan L. Cox

Arrays and Pointers in C. Alan L. Cox Arrays and Pointers in C Alan L. Cox alc@rice.edu Objectives Be able to use arrays, pointers, and strings in C programs Be able to explain the representation of these data types at the machine level, including

More information

Chapter 15 Notes, Stewart 7e

Chapter 15 Notes, Stewart 7e Contents 15.2 Iterated Integrals..................................... 2 15.3 Double Integrals over General Regions......................... 5 15.4 Double Integrals in Polar Coordinates..........................

More information

2. Numbers In, Numbers Out

2. Numbers In, Numbers Out COMP1917: Computing 1 2. Numbers In, Numbers Out Reading: Moffat, Chapter 2. COMP1917 15s2 2. Numbers In, Numbers Out 1 The Art of Programming Think about the problem Write down a proposed solution Break

More information

SECTION 4.5: GRAPHS OF SINE AND COSINE FUNCTIONS

SECTION 4.5: GRAPHS OF SINE AND COSINE FUNCTIONS SECTION 4.5: GRAPHS OF SINE AND COSINE FUNCTIONS 4.33 PART A : GRAPH f ( θ ) = sinθ Note: We will use θ and f ( θ) for now, because we would like to reserve x and y for discussions regarding the Unit Circle.

More information

Programming Language B

Programming Language B Programming Language B Takako Nemoto (JAIST) 17 December Takako Nemoto (JAIST) 17 December 1 / 17 A tip for the last homework 1 Do Exercise 9-5 ( 9-5) in p.249 (in the latest edtion). The type of the second

More information

Program Organization and Comments

Program Organization and Comments C / C++ PROGRAMMING Program Organization and Comments Copyright 2013 Dan McElroy Programming Organization The layout of a program should be fairly straight forward and simple. Although it may just look

More information

Software Development With Emacs: The Edit-Compile-Debug Cycle

Software Development With Emacs: The Edit-Compile-Debug Cycle Software Development With Emacs: The Edit-Compile-Debug Cycle Luis Fernandes Department of Electrical and Computer Engineering Ryerson Polytechnic University August 8, 2017 The Emacs editor permits the

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

Approximately a Test II CPSC 206

Approximately a Test II CPSC 206 Approximately a Test II CPSC 206 Sometime in history based on Kelly and Pohl Last name, First Name Last 5 digits of ID Write your section number(s): All parts of this exam are required unless plainly and

More information

FUNCTIONS POINTERS. Pointers. Functions

FUNCTIONS POINTERS. Pointers. Functions Functions Pointers FUNCTIONS C allows a block of code to be separated from the rest of the program and named. These blocks of code or modules are called functions. Functions can be passed information thru

More information

Contents. A Review of C language. Visual C Visual C++ 6.0

Contents. A Review of C language. Visual C Visual C++ 6.0 A Review of C language C++ Object Oriented Programming Pei-yih Ting NTOU CS Modified from www.cse.cuhk.edu.hk/~csc2520/tuto/csc2520_tuto01.ppt 1 2 3 4 5 6 7 8 9 10 Double click 11 12 Compile a single source

More information

Lecture 3. Understanding of OPenGL programming

Lecture 3. Understanding of OPenGL programming Lecture 3 Understanding of OPenGL programming What is OpenGL GL: stands for Graphic Library Software interface for rendering purposes for 2D or 3D geometric data objects. Various Pieces gl: The basic libraries.

More information

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco CS 326 Operating Systems C Programming Greg Benson Department of Computer Science University of San Francisco Why C? Fast (good optimizing compilers) Not too high-level (Java, Python, Lisp) Not too low-level

More information

Polar Coordinates. Calculus 2 Lia Vas. If P = (x, y) is a point in the xy-plane and O denotes the origin, let

Polar Coordinates. Calculus 2 Lia Vas. If P = (x, y) is a point in the xy-plane and O denotes the origin, let Calculus Lia Vas Polar Coordinates If P = (x, y) is a point in the xy-plane and O denotes the origin, let r denote the distance from the origin O to the point P = (x, y). Thus, x + y = r ; θ be the angle

More information

Trigonometric Functions of Any Angle

Trigonometric Functions of Any Angle Trigonometric Functions of Any Angle MATH 160, Precalculus J. Robert Buchanan Department of Mathematics Fall 2011 Objectives In this lesson we will learn to: evaluate trigonometric functions of any angle,

More information

Arrays. An array is a collection of several elements of the same type. An array variable is declared as array name[size]

Arrays. An array is a collection of several elements of the same type. An array variable is declared as array name[size] (November 10, 2009 2.1 ) Arrays An array is a collection of several elements of the same type. An array variable is declared as type array name[size] I The elements are numbered as 0, 1, 2... size-1 I

More information

gcc hello.c a.out Hello, world gcc -o hello hello.c hello Hello, world

gcc hello.c a.out Hello, world gcc -o hello hello.c hello Hello, world alun@debian:~$ gcc hello.c alun@debian:~$ a.out Hello, world alun@debian:~$ gcc -o hello hello.c alun@debian:~$ hello Hello, world alun@debian:~$ 1 A Quick guide to C for Networks and Operating Systems

More information

Overview (1A) Young Won Lim 9/14/17

Overview (1A) Young Won Lim 9/14/17 Overview (1A) Copyright (c) 2009-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later

More information

CS 1713 Introduction to Programming II

CS 1713 Introduction to Programming II CS 1713 Introduction to Programming II Spring 2014 Midterm 2 -- April 24, 2014 You have 75 min. Good luck. You can use the 2-page C reference card posted in the class web page. Name: Score:./100 Background

More information

Question 1. [5 points] Consider the following partially-complete program, which begins on the left and continues on the right: HERE

Question 1. [5 points] Consider the following partially-complete program, which begins on the left and continues on the right: HERE CS 101, Spring 2017 May 4th Exam 4 Name: Question 1. [5 points] Consider the following partially-complete program, which begins on the void set_to_ten(int *p); void set_to_ten(int *p) { *p = 10; int x

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

Laboratory 1 Semester 1 11/12

Laboratory 1 Semester 1 11/12 CS2106 National University of Singapore School of Computing Laboratory 1 Semester 1 11/12 MATRICULATION NUMBER: In this lab exercise, you will get familiarize with some basic UNIX commands, editing and

More information

1 Trigonometry. Copyright Cengage Learning. All rights reserved.

1 Trigonometry. Copyright Cengage Learning. All rights reserved. 1 Trigonometry Copyright Cengage Learning. All rights reserved. 1.1 Radian and Degree Measure Copyright Cengage Learning. All rights reserved. Objectives Describe angles. Use radian measure. Use degree

More information

CS 1713 Introduction to Programming II

CS 1713 Introduction to Programming II CS 1713 Introduction to Programming II Spring 2014 Midterm 2 -- April 24, 2014 You have 75 min. Good luck. You can use the 2-page C reference card posted in the class web page. Name: Score:./100 Background

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

1001ICT Introduction To Programming Lecture Notes

1001ICT Introduction To Programming Lecture Notes 1001ICT Introduction To Programming Lecture Notes School of Information and Communication Technology Griffith University Semester 1, 2015 1 M Environment console M.1 Purpose This environment supports programming

More information

Overview (1A) Young Won Lim 9/9/17

Overview (1A) Young Won Lim 9/9/17 Overview (1A) Copyright (c) 2009-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later

More information

CpSc 1010, Fall 2014 Lab 10: Command-Line Parameters (Week of 10/27/2014)

CpSc 1010, Fall 2014 Lab 10: Command-Line Parameters (Week of 10/27/2014) CpSc 1010, Fall 2014 Lab 10: Command-Line Parameters (Week of 10/27/2014) Goals Demonstrate proficiency in the use of the switch construct and in processing parameter data passed to a program via the command

More information

School of Computer Science Introduction to Algorithms and Programming Winter Midterm Examination # 1 Wednesday, February 11, 2015

School of Computer Science Introduction to Algorithms and Programming Winter Midterm Examination # 1 Wednesday, February 11, 2015 Page 1 of 8 School of Computer Science 60-141-01 Introduction to Algorithms and Programming Winter 2015 Midterm Examination # 1 Wednesday, February 11, 2015 Marking Exemplar Duration of examination: 75

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

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

Flex and lexical analysis

Flex and lexical analysis Flex and lexical analysis From the area of compilers, we get a host of tools to convert text files into programs. The first part of that process is often called lexical analysis, particularly for such

More information

CSE 1320 INTERMEDIATE PROGRAMMING - OVERVIEW AND DATA TYPES

CSE 1320 INTERMEDIATE PROGRAMMING - OVERVIEW AND DATA TYPES CSE 1320 INTERMEDIATE PROGRAMMING - OVERVIEW AND DATA TYPES Mingon Kang The University of Texas at Arlington C History ANSI C, also known C89(ANSI X3.159-1989) and C90 (ISO/IEC 9899:1990) ANSI: American

More information

Game Engineering: 2D

Game Engineering: 2D Game Engineering: 2D CS420-2010F-07 Objects in 2D David Galles Department of Computer Science University of San Francisco 07-0: Representing Polygons We want to represent a simple polygon Triangle, rectangle,

More information

2. Numbers In, Numbers Out

2. Numbers In, Numbers Out REGZ9280: Global Education Short Course - Engineering 2. Numbers In, Numbers Out Reading: Moffat, Chapter 2. REGZ9280 14s2 2. Numbers In, Numbers Out 1 The Art of Programming Think about the problem Write

More information

MAT 271 Recitation. MAT 271 Recitation. Sections 10.1,10.2. Lindsey K. Gamard, ASU SoMSS. 22 November 2013

MAT 271 Recitation. MAT 271 Recitation. Sections 10.1,10.2. Lindsey K. Gamard, ASU SoMSS. 22 November 2013 MAT 271 Recitation Sections 10.1,10.2 Lindsey K. Gamard, ASU SoMSS 22 November 2013 Agenda Today s agenda: 1. Introduction to concepts from 10.1 and 10.2 2. Example problems 3. Groupwork Section 10.1 Introduction

More information

Friday, September 16, Lab Notes. Command line arguments More pre-processor options Programs: Finish Program 1, begin Program 2 due next week

Friday, September 16, Lab Notes. Command line arguments More pre-processor options Programs: Finish Program 1, begin Program 2 due next week Friday, September 16, 2016 Lab Notes Topics for today Redirection of input and output Command line arguments More pre-processor options Programs: Finish Program 1, begin Program 2 due next week 1. Redirection

More information

is a plane curve and the equations are parametric equations for the curve, with parameter t.

is a plane curve and the equations are parametric equations for the curve, with parameter t. MATH 2412 Sections 6.3, 6.4, and 6.5 Parametric Equations and Polar Coordinates. Plane Curves and Parametric Equations Suppose t is contained in some interval I of the real numbers, and = f( t), = gt (

More information

Basics of Java Programming

Basics of Java Programming Basics of Java Programming Lecture 2 COP 3252 Summer 2017 May 16, 2017 Components of a Java Program statements - A statement is some action or sequence of actions, given as a command in code. A statement

More information

Carleton University Department of Systems and Computer Engineering SYSC Foundations of Imperative Programming - Winter 2012

Carleton University Department of Systems and Computer Engineering SYSC Foundations of Imperative Programming - Winter 2012 Carleton University Department of Systems and Computer Engineering SYSC 2006 - Foundations of Imperative Programming - Winter 2012 Lab 2 - C Functions Objective The objective of this lab is to write some

More information

Hello, World! in C. Johann Myrkraverk Oskarsson October 23, The Quintessential Example Program 1. I Printing Text 2. II The Main Function 3

Hello, World! in C. Johann Myrkraverk Oskarsson October 23, The Quintessential Example Program 1. I Printing Text 2. II The Main Function 3 Hello, World! in C Johann Myrkraverk Oskarsson October 23, 2018 Contents 1 The Quintessential Example Program 1 I Printing Text 2 II The Main Function 3 III The Header Files 4 IV Compiling and Running

More information

The diagram above shows a sketch of the curve C with parametric equations

The diagram above shows a sketch of the curve C with parametric equations 1. The diagram above shows a sketch of the curve C with parametric equations x = 5t 4, y = t(9 t ) The curve C cuts the x-axis at the points A and B. (a) Find the x-coordinate at the point A and the x-coordinate

More information

CS-201 Introduction to Programming with Java

CS-201 Introduction to Programming with Java CS-201 Introduction to Programming with Java California State University, Los Angeles Computer Science Department Lecture V: Mathematical Functions, Characters, and Strings Introduction How would you estimate

More information

Midterm Exam 2 Solutions, C programming

Midterm Exam 2 Solutions, C programming Midterm Exam 2 Solutions, C programming April 26, 2010 Rules: Open book, open notes, open any printed or handwritten material. No electronic devices (except a music player). If you use a music player nobody

More information

Polar Coordinates. 2, π and ( )

Polar Coordinates. 2, π and ( ) Polar Coordinates Up to this point we ve dealt exclusively with the Cartesian (or Rectangular, or x-y) coordinate system. However, as we will see, this is not always the easiest coordinate system to work

More information

Supplementary Material: The Rotation Matrix

Supplementary Material: The Rotation Matrix Supplementary Material: The Rotation Matrix Computer Science 4766/6778 Department of Computer Science Memorial University of Newfoundland January 16, 2014 COMP 4766/6778 (MUN) The Rotation Matrix January

More information

CCE1111 Programming for Engineers [C Programming Language]

CCE1111 Programming for Engineers [C Programming Language] are collection of characters. Unfortunately C does not has a primitive data type for strings and therefore an array of characters is used to represent a string. The following code snippet illustrates a

More information

INTRODUCTION TO C++ FUNCTIONS. Dept. of Electronic Engineering, NCHU. Original slides are from

INTRODUCTION TO C++ FUNCTIONS. Dept. of Electronic Engineering, NCHU. Original slides are from INTRODUCTION TO C++ FUNCTIONS Original slides are from http://sites.google.com/site/progntut/ Dept. of Electronic Engineering, NCHU Outline 2 Functions: Program modules in C Function Definitions Function

More information

pointers + memory double x; string a; int x; main overhead int y; main overhead

pointers + memory double x; string a; int x; main overhead int y; main overhead pointers + memory computer have memory to store data. every program gets a piece of it to use as we create and use more variables, more space is allocated to a program memory int x; double x; string a;

More information

CS2141 Software Development using C/C++ C++ Basics

CS2141 Software Development using C/C++ C++ Basics CS2141 Software Development using C/C++ C++ Basics Integers Basic Types Can be short, long, or just plain int C++ does not define the size of them other than short

More information

E-BOOK // CONVERT TO RECTANGULAR COORDINATES DOCUMENT

E-BOOK // CONVERT TO RECTANGULAR COORDINATES DOCUMENT 19 February, 2018 E-BOOK // CONVERT TO RECTANGULAR COORDINATES DOCUMENT Document Filetype: PDF 533.05 KB 0 E-BOOK // CONVERT TO RECTANGULAR COORDINATES DOCUMENT For more help a students can connect to

More information