CSCE 110 Dr. Amr Goneid Exercise Sheet (6): Exercises on Structs and Dynamic Lists

Size: px
Start display at page:

Download "CSCE 110 Dr. Amr Goneid Exercise Sheet (6): Exercises on Structs and Dynamic Lists"

Transcription

1 CSCE 110 Dr. Amr Goneid Exercise Sheet (6): Exercises on Structs and Dynamic Lists Exercises on Structs (Solutions) (a) Define a struct data type location with integer members row, column Define another struct data type pixeltype with members: color (0 for black and 1 for white) and position (a struct of type location as defined above). (b) A 2-D array A [ ] [ ] is of type pixeltype and represents a black and white image of size (n x m). Implement a function flipud (A) that uses the above struct definitions to receive the image and return it upside down. struct location int row, column; ; struct pixeltype int color; location position; ; const int N =...; const M =...; int n = N; int m = M; void flipud (pixeltype A [ ] [M], int n, int m) pixeltype temp; for (i = 0; i < n/2; i++) for (j = 0; j < m; j++) temp = A[i][j]; A[i][j] = A[n-i-1][j]; A[n-i-1][j] = temp; Declare a struct type fraction for a fractional number with numerator num and a denominator denom, both are integers. Write a function fadd (x,y,z) to receive two fractional numbers (x) and (y) and return the fractional variable z = x + y according to the rule: If x = a / b and y = c / d, then z = (ad + cb) / (bd) struct fraction int num, denom; ; void fadd (fraction x, fraction y, fraction & z) z.num = x.num * y.denom + y.num * x.denom; z.denom = x.denom * y.denom;

2 Declare a struct type item for an item with weight and total price, both are of type float. Write a function maxval (x,y,z) to receive two items (x) and (y) and return the more valuable item (z), i.e. the item with the higher price per weight ratio. struct item float weight, price; ; void maxval (item x, item y, item & z) if ((x.price / x.weight) >= (y.price / y.weight)) z = x else z = y; Declare a struct type for a point in 3-D space with coordinates (x,y,z). Write a function distance(a,b) that receives two points (a) and (b) in 3-D space and returns the distance between them. struct point float x, y, z; ; float distance (point a, point b) float dx, dy, dz; dx = a.x b.x; dy =a.y b.y; dz =a.z b.z; return sqrt (dx*dx + dy*dy + dz*dz) Declare a struct type for a complex number with a real part and an imaginary part, both of type double. Write a function cmult (a,b,c) to receive two complex variables (a) and (b) and return the complex variable c = a*b according to the rule: If a = x1 + j y1 and b = x2 + j y2 then c = (x1.x2 y1.y2) + j (x1.y2 + x2.y1) struct complex double x, y; ; void cmult (complex a, complex b, complex &c) double Rec, Imc; Rec = a.x * b.x a.y * b.y; Imc = a.x * b.y + b.x * a.y; c.x = Rec; c.y = Imc;

3 A color image is stored as a 2-D array A[ ][ ] of pixels, with N rows and M columns. Each pixel A[i][j] is represented as a struct with three integer values representing its color components (Red, Green, Blue). To convert the pixel color to grey-level, we take the average of the three color components (rounded to the nearest integer) as the brightness. Write a function to receive such array and return another array B[ ][ ] containing the brightness of each pixel in the image. Consider N and M to be global constants. Solution const int N =...; const int M =...; struct pixel int red, green, blue; ; void Brightness (pixel A[ ][M], int B[ ][M]) int i, j, b; pixel p; for (i = 0; i < N; i++) for (j = 0; j < M; j++) p = A[i][j]; b = (p.red + p.green + p.blue)/ ; // or b = floor((p.red + p.green + p.blue)/ ); B[i][j] = b; Question 1 (15 points) A color image is stored as a 2-D array A[ ][ ] of pixels of N rows and M columns. Each pixel is represented as a struct with three integer values representing its color components (Red, Green, Blue). A sub-image is a block with the first H rows and first W columns, where H N and W M. Write a function to receive the image and the two integers H, W and return a pointer to a 1-D dynamic array containing the Green component of the sub-image defined by H and W. Consider N and M to be global constants. Declare a struct type item for an item with weight and total price, both are of type float. Consider the value of an item to be the ratio of price to weight. Write a recursive function to receive: a 1-D array of items, a starting index (s) an end index (e) a number (V) of type float a number (W) of type float The function should return the number of valuable items. We will define a valuable item as that having a weight less than (W) and a value greater than (V).

4 Declare a struct type item for an item with weight and total price, both are of type float. Consider the value of an item to be the ratio of price to weight. Write a function maxval to receive a 1-D array of items of size (N) and a number (k) of type float and return the item with the value nearest to (k).

5 Exercises on Dynamic Lists (Solutions) Assume the following declarations: struct node int info; node *next; node *p; Draw a diagram representing the nodes and pointers generated by the following code: node *h = NULL; int n = 1357; do p = new node; p-> info = n % 10; p -> next = h; h = p; n = n/10; while (n > 0); Final Result: h Assume that the sequence of integers (17, 20, 50, 90) is already stored in a simple linked list of the structure given above in the order given ( first node contains 17). Trace the following: void What ( node *head ) node *p, *q, *r ; p = head ; q = NULL ; while (p!= NULL) r = q ; q = p ; p = p->ptr ; q->ptr = r ; head = q ; What will this function do if used on the above list? Left as an exercise. Assume the following declarations: struct node char info; node *next; node *p; node *h = NULL; node *c = h; Draw a diagram representing the nodes and pointers generated by the following code: string s = DATA LIST ; for (int i = 0; i < s.length( ); i++) p = new node; p-> info = s.at(i); p -> next = NULL; if (c == NULL) h = p; c = p; else c -> next = p; c = c -> next;

6 Solution The given code will insert the characters of the string s into a linked list of nodes in the same order, i.e., head BAT CAT DOG Given the above list and assuming the following declaration: struct node string info; node *ptr; Trace the following function to show the list after the function call: void What ( node *head ) node *p, *q, *r ; p = head ; q = NULL ; while (p!= NULL) r = q ; q = p ; p = p->ptr ; q->ptr = r ; head = q ; What is the objective of this function?

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

CSCE 110 Dr. Amr Goneid Exercise Sheet (7): Exercises on Recursion

CSCE 110 Dr. Amr Goneid Exercise Sheet (7): Exercises on Recursion CSCE 110 Dr. Amr Goneid Exercise Sheet (7): Exercises on Recursion Consider the following recursive function: int what ( int x, int y) if (x > y) return what (x-y, y); else if (y > x) return what (x, y-x);

More information

Assignment #4: Scalar Field Visualization 3D: Cutting Plane, Wireframe Iso-surfacing

Assignment #4: Scalar Field Visualization 3D: Cutting Plane, Wireframe Iso-surfacing Goals: Assignment #4: Scalar Field Visualization 3D: Cutting Plane, Wireframe Iso-surfacing Due Sept. 28, before midnight With the results from your assignments #2 and #3, the first goal of this assignment

More information

Module 01 Processing Recap

Module 01 Processing Recap Module 01 Processing Recap Processing is a language a library an environment Variables A variable is a named value. It has a type (which can t change) and a current value (which can change). Variables

More information

CSCE 110 Dr. Amr Goneid Exercise Sheet (7): Exercises on Recursion (Solutions)

CSCE 110 Dr. Amr Goneid Exercise Sheet (7): Exercises on Recursion (Solutions) CSCE 110 Dr. Amr Goneid Exercise Sheet (7): Exercises on Recursion (Solutions) Consider the following recursive function: int what ( int x, int y) if (x > y) return what (x-y, y); else if (y > x) return

More information

Module 01 Processing Recap. CS 106 Winter 2018

Module 01 Processing Recap. CS 106 Winter 2018 Module 01 Processing Recap CS 106 Winter 2018 Processing is a language a library an environment Variables A variable is a named value. It has a type (which can t change) and a current value (which can

More information

CSCE 110 PROGRAMMING FUNDAMENTALS. Prof. Amr Goneid AUC Part 7. 1-D & 2-D Arrays

CSCE 110 PROGRAMMING FUNDAMENTALS. Prof. Amr Goneid AUC Part 7. 1-D & 2-D Arrays CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 7. 1-D & 2-D Arrays Prof. Amr Goneid, AUC 1 Arrays Prof. Amr Goneid, AUC 2 1-D Arrays Data Structures The Array Data Type How to Declare

More information

CSCE 110 PROGRAMMING FUNDAMENTALS

CSCE 110 PROGRAMMING FUNDAMENTALS CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 2. Overview of C++ Prof. Amr Goneid, AUC 1 Overview of C++ Prof. Amr Goneid, AUC 2 Overview of C++ Historical C++ Basics Some Library

More information

Midterm 1 topics (in one slide) Bits and bitwise operations. Outline. Unsigned and signed integers. Floating point numbers. Number representation

Midterm 1 topics (in one slide) Bits and bitwise operations. Outline. Unsigned and signed integers. Floating point numbers. Number representation Midterm 1 topics (in one slide) CSci 2021: Review Lecture 1 Stephen McCamant University of Minnesota, Computer Science & Engineering Number representation Bits and bitwise operators Unsigned and signed

More information

Scan Converting Lines

Scan Converting Lines Scan Conversion 1 Scan Converting Lines Line Drawing Draw a line on a raster screen between two points What s wrong with the statement of the problem? it doesn t say anything about which points are allowed

More information

Name: SID: LAB Section: Lab 6 - Part 1: Pixels and Triangle Rasterization

Name: SID: LAB Section: Lab 6 - Part 1: Pixels and Triangle Rasterization Name: SID: LAB Section: Lab 6 - Part 1: Pixels and Triangle Rasterization 1. Coordinate space conversions. In OpenGL, the coordinates of a vertex in model-view space can be converted to NPC coordinates,

More information

CSCE 210 Dr. Amr Goneid Exercises (1): Stacks, Queues. Stacks

CSCE 210 Dr. Amr Goneid Exercises (1): Stacks, Queues. Stacks CSCE 210 Dr. Amr Goneid Exercises (1): Stacks, Queues Stacks Given an input sequence of integers 1, 2, 3, 4, 5, 6 and only three operations on a stack: 1. C: Copy next input directly to output list. 2.

More information

/INFOMOV/ Optimization & Vectorization. J. Bikker - Sep-Nov Lecture 5: SIMD (1) Welcome!

/INFOMOV/ Optimization & Vectorization. J. Bikker - Sep-Nov Lecture 5: SIMD (1) Welcome! /INFOMOV/ Optimization & Vectorization J. Bikker - Sep-Nov 2018 - Lecture 5: SIMD (1) Welcome! INFOMOV Lecture 5 SIMD (1) 2 Meanwhile, on ars technica INFOMOV Lecture 5 SIMD (1) 3 Meanwhile, the job market

More information

COMPUTER APPLICATION

COMPUTER APPLICATION Total No. of Printed Pages 16 HS/XII/A.Sc.Com/CAP/14 2 0 1 4 COMPUTER APPLICATION ( Science / Arts / Commerce ) ( Theory ) Full Marks : 70 Time : 3 hours The figures in the margin indicate full marks for

More information

Object Oriented Programming Using C++ Mathematics & Computing IET, Katunayake

Object Oriented Programming Using C++ Mathematics & Computing IET, Katunayake Assigning Values // Example 2.3(Mathematical operations in C++) float a; cout > a; cout

More information

CSCE 110 PROGRAMMING FUNDAMENTALS

CSCE 110 PROGRAMMING FUNDAMENTALS CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 16. Linked Lists Prof. amr Goneid, AUC 1 Linked Lists Prof. amr Goneid, AUC 2 Linked Lists The Linked List Structure Some Linked List

More information

CHAPTER 4 FUNCTIONS. 4.1 Introduction

CHAPTER 4 FUNCTIONS. 4.1 Introduction CHAPTER 4 FUNCTIONS 4.1 Introduction Functions are the building blocks of C++ programs. Functions are also the executable segments in a program. The starting point for the execution of a program is main

More information

CSCE 2014 Final Exam Spring Version A

CSCE 2014 Final Exam Spring Version A CSCE 2014 Final Exam Spring 2017 Version A Student Name: Student UAID: Instructions: This is a two-hour exam. Students are allowed one 8.5 by 11 page of study notes. Calculators, cell phones and computers

More information

Tema 6: Dynamic memory

Tema 6: Dynamic memory Tema 6: Programming 2 and vectors defined with 2013-2014 and Index and vectors defined with and 1 2 3 and vectors defined with and and vectors defined with and Size is constant and known a-priori when

More information

Arrays. CS10001: Programming & Data Structures. Pallab Dasgupta Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur

Arrays. CS10001: Programming & Data Structures. Pallab Dasgupta Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur Arrays CS10001: Programming & Data Structures Pallab Dasgupta Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur Array Many applications require multiple data items that have common

More information

C Pointers. 6th April 2017 Giulio Picierro

C Pointers. 6th April 2017 Giulio Picierro C Pointers 6th April 07 Giulio Picierro Functions Return type Function name Arguments list Function body int sum(int a, int b) { return a + b; } Return statement (return keyword

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

Introduction to C Language (M3-R )

Introduction to C Language (M3-R ) Introduction to C Language (M3-R4-01-18) 1. Each question below gives a multiple choice of answers. Choose the most appropriate one and enter in OMR answer sheet supplied with the question paper, following

More information

M1-R4: Programing and Problem Solving using C (JAN 2019)

M1-R4: Programing and Problem Solving using C (JAN 2019) M1-R4: Programing and Problem Solving using C (JAN 2019) Max Marks: 100 M1-R4-07-18 DURATION: 03 Hrs 1. Each question below gives a multiple choice of answers. Choose the most appropriate one and enter

More information

CSCE 110 PROGRAMMING FUNDAMENTALS

CSCE 110 PROGRAMMING FUNDAMENTALS CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 15. Dictionaries (1): A Key Table Class Prof. amr Goneid, AUC 1 Dictionaries(1): A Key Table Class Prof. Amr Goneid, AUC 2 A Key Table

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

Midterm Exam #2 Spring (1:00-3:00pm, Friday, March 15)

Midterm Exam #2 Spring (1:00-3:00pm, Friday, March 15) Print Your Name: Signature: USC email address: CSCI 101L Fundamentals of Computer Programming Midterm Exam #2 Spring 2013 (1:00-3:00pm, Friday, March 15) Instructor: Prof Tejada Problem #1 (20 points):

More information

CS 543: Computer Graphics Lecture 3 (Part I): Fractals. Emmanuel Agu

CS 543: Computer Graphics Lecture 3 (Part I): Fractals. Emmanuel Agu CS 543: Computer Graphics Lecture 3 (Part I: Fractals Emmanuel Agu What are Fractals? Mathematical expressions Approach infinity in organized way Utilizes recursion on computers Popularized by Benoit Mandelbrot

More information

Output Primitives Lecture: 3. Lecture 3. Output Primitives. Assuming we have a raster display, a picture is completely specified by:

Output Primitives Lecture: 3. Lecture 3. Output Primitives. Assuming we have a raster display, a picture is completely specified by: Lecture 3 Output Primitives Assuming we have a raster display, a picture is completely specified by: - A set of intensities for the pixel positions in the display. - A set of complex objects, such as trees

More information

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures The main body and cout Agenda 1 Fundamental data types Declarations and definitions Control structures References, pass-by-value vs pass-by-references The main body and cout 2 C++ IS AN OO EXTENSION OF

More information

CSc 372 Comparative Programming Languages

CSc 372 Comparative Programming Languages CSc 372 Comparative Programming Languages 8 : Haskell Function Examples Christian Collberg collberg+372@gmail.com Department of Computer Science University of Arizona Copyright c 2005 Christian Collberg

More information

CSc 372. Comparative Programming Languages. 8 : Haskell Function Examples. Department of Computer Science University of Arizona

CSc 372. Comparative Programming Languages. 8 : Haskell Function Examples. Department of Computer Science University of Arizona 1/43 CSc 372 Comparative Programming Languages 8 : Haskell Function Examples Department of Computer Science University of Arizona collberg@gmail.com Copyright c 2013 Christian Collberg Functions over Lists

More information

CS Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015

CS Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015 CS 141 - Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015 You may take this test with you after the test, but you must turn in your answer sheet. This test has the following sections:

More information

CS 4731: Computer Graphics Lecture 21: Raster Graphics: Drawing Lines. Emmanuel Agu

CS 4731: Computer Graphics Lecture 21: Raster Graphics: Drawing Lines. Emmanuel Agu CS 4731: Computer Graphics Lecture 21: Raster Graphics: Drawing Lines Emmanuel Agu 2D Graphics Pipeline Clipping Object World Coordinates Applying world window Object subset window to viewport mapping

More information

Assignment #3: Scalar Field Visualization 3D: Cutting Plane, Wireframe Iso-surfacing, and Direct Volume Rendering

Assignment #3: Scalar Field Visualization 3D: Cutting Plane, Wireframe Iso-surfacing, and Direct Volume Rendering Assignment #3: Scalar Field Visualization 3D: Cutting Plane, Wireframe Iso-surfacing, and Direct Volume Rendering Goals: Due October 9 th, before midnight With the results from your assignement#2, the

More information

Solution Notes. COMP 151: Terms Test

Solution Notes. COMP 151: Terms Test Family Name:.............................. Other Names:............................. ID Number:............................... Signature.................................. Solution Notes COMP 151: Terms

More information

Type checking of statements We change the start rule from P D ; E to P D ; S and add the following rules for statements: S id := E

Type checking of statements We change the start rule from P D ; E to P D ; S and add the following rules for statements: S id := E Type checking of statements We change the start rule from P D ; E to P D ; S and add the following rules for statements: S id := E if E then S while E do S S ; S Type checking of statements The purpose

More information

COP 3223 Introduction to Programming with C - Study Union - Fall 2017

COP 3223 Introduction to Programming with C - Study Union - Fall 2017 COP 3223 Introduction to Programming with C - Study Union - Fall 2017 Chris Marsh and Matthew Villegas Contents 1 Code Tracing 2 2 Pass by Value Functions 4 3 Statically Allocated Arrays 5 3.1 One Dimensional.................................

More information

Raster Scan Displays. Framebuffer (Black and White)

Raster Scan Displays. Framebuffer (Black and White) Raster Scan Displays Beam of electrons deflected onto a phosphor coated screen Phosphors emit light when excited by the electrons Phosphor brightness decays -- need to refresh the display Phosphors make

More information

Painter s HSR Algorithm

Painter s HSR Algorithm Painter s HSR Algorithm Render polygons farthest to nearest Similar to painter layers oil paint Viewer sees B behind A Render B then A Depth Sort Requires sorting polygons (based on depth) O(n log n) complexity

More information

CSCE Practice Midterm. Data Types

CSCE Practice Midterm. Data Types CSCE 2004 - Practice Midterm This midterm exam was given in class several years ago. Work each of the following questions on your own. Once you are done, check your answers. For any questions whose answers

More information

Department of Computer Science & Engineering Indian Institute of Technology Kharagpur. Practice Sheet #06

Department of Computer Science & Engineering Indian Institute of Technology Kharagpur. Practice Sheet #06 Department of Computer Science & Engineering Indian Institute of Technology Kharagpur Practice Sheet #06 Topic: Recursion in C 1. What string does the following program print? #include #include

More information

5200/7200 Fall 2007 Concurrence theorems for triangles

5200/7200 Fall 2007 Concurrence theorems for triangles 5200/7200 Fall 2007 Concurrence theorems for triangles There are two basic concurrence theorems for triangles that hold in neutral geometry, that of medians and of angle bisectors, but it seems hard to

More information

P.G.TRB - COMPUTER SCIENCE. c) data processing language d) none of the above

P.G.TRB - COMPUTER SCIENCE. c) data processing language d) none of the above P.G.TRB - COMPUTER SCIENCE Total Marks : 50 Time : 30 Minutes 1. C was primarily developed as a a)systems programming language b) general purpose language c) data processing language d) none of the above

More information

COP 3223 Introduction to Programming with C - Study Union - Fall 2017

COP 3223 Introduction to Programming with C - Study Union - Fall 2017 COP 3223 Introduction to Programming with C - Study Union - Fall 2017 Chris Marsh and Matthew Villegas Contents 1 Code Tracing 2 2 Pass by Value Functions 4 3 Statically Allocated Arrays 5 3.1 One Dimensional.................................

More information

Data Structures Unit 02

Data Structures Unit 02 Data Structures Unit 02 Bucharest University of Economic Studies Memory classes, Bit structures and operators, User data types Memory classes Define specific types of variables in order to differentiate

More information

Low-Level C Programming. Memory map Pointers Arrays Structures

Low-Level C Programming. Memory map Pointers Arrays Structures Low-Level C Programming Memory map Pointers Arrays Structures Memory Map 0x7FFF_FFFF Binaries load at 0x20000 by default Stack start set by binary when started Stack grows downwards You will need one stack

More information

(4) Find the syntax error(s), if any, in the following program: #include main() int x[5],*y,z[5]; for(i=0;i<5;i++) x[i]=i; z[i]=i+3; y=z; x=y; (5) Rew

(4) Find the syntax error(s), if any, in the following program: #include main() int x[5],*y,z[5]; for(i=0;i<5;i++) x[i]=i; z[i]=i+3; y=z; x=y; (5) Rew (1)Rewrite the following program after removing the syntactical error(s), if any Underline each correction, struct TV char Manu_name[20]; char Tv_Type; int Price = 17000; New Tv; gets(manu_name); gets(tv_type);

More information

Test 1: CPS 100. Owen Astrachan. October 11, 2000

Test 1: CPS 100. Owen Astrachan. October 11, 2000 Test 1: CPS 100 Owen Astrachan October 11, 2000 Name: Login: Honor code acknowledgment (signature) Problem 1 Problem 2 Problem 3 Problem 4 TOTAL: value 30 pts. 16 pts. 12 pts. 20 pts. 78 pts. grade This

More information

Pointers, Dynamic Data, and Reference Types

Pointers, Dynamic Data, and Reference Types Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation The new operator The delete operator Dynamic Memory Allocation for Arrays 1 C++ Data Types simple

More information

Signature: ECE 551 Midterm Exam

Signature: ECE 551 Midterm Exam Name: ECE 551 Midterm Exam NetID: There are 7 questions, with the point values as shown below. You have 75 minutes with a total of 75 points. Pace yourself accordingly. This exam must be individual work.

More information

Consider the following statements. string str1 = "ABCDEFGHIJKLM"; string str2; After the statement str2 = str1.substr(1,4); executes, the value of str2 is " ". Given the function prototype: float test(int,

More information

Actually, C provides another type of variable which allows us to do just that. These are called dynamic variables.

Actually, C provides another type of variable which allows us to do just that. These are called dynamic variables. When a program is run, memory space is immediately reserved for the variables defined in the program. This memory space is kept by the variables until the program terminates. These variables are called

More information

A506 / C201 Computer Programming II Placement Exam Sample Questions. For each of the following, choose the most appropriate answer (2pts each).

A506 / C201 Computer Programming II Placement Exam Sample Questions. For each of the following, choose the most appropriate answer (2pts each). A506 / C201 Computer Programming II Placement Exam Sample Questions For each of the following, choose the most appropriate answer (2pts each). 1. Which of the following functions is causing a temporary

More information

ESC101N: Fundamentals of Computing End-sem st semester

ESC101N: Fundamentals of Computing End-sem st semester ESC101N: Fundamentals of Computing End-sem 2010-11 1st semester Instructor: Arnab Bhattacharya 8:00-11:00am, 15th November, 2010 Instructions 1. Please write your name, roll number and section below. 2.

More information

Computer Graphics. Lecture 2. Doç. Dr. Mehmet Gokturk

Computer Graphics. Lecture 2. Doç. Dr. Mehmet Gokturk Computer Graphics Lecture 2 Doç. Dr. Mehmet Gokturk Mathematical Foundations l Hearn and Baker (A1 A4) appendix gives good review l Some of the mathematical tools l Trigonometry l Vector spaces l Points,

More information

Department of Computer Science & Engineering Indian Institute of Technology Kharagpur. Practice Sheet #04

Department of Computer Science & Engineering Indian Institute of Technology Kharagpur. Practice Sheet #04 Department of Computer Science & Engineering Indian Institute of Technology Kharagpur Topic: Arrays and Strings Practice Sheet #04 Date: 24-01-2017 Instructions: For the questions consisting code segments,

More information

Subject: Fundamental of Computer Programming 2068

Subject: Fundamental of Computer Programming 2068 Subject: Fundamental of Computer Programming 2068 1 Write an algorithm and flowchart to determine whether a given integer is odd or even and explain it. Algorithm Step 1: Start Step 2: Read a Step 3: Find

More information

C-types: basic & constructed. C basic types: int, char, float, C constructed types: pointer, array, struct

C-types: basic & constructed. C basic types: int, char, float, C constructed types: pointer, array, struct C-types: basic & constructed C basic types: int, char, float, C constructed types: pointer, array, struct Memory Management Code Global variables in file (module) Local static variables in functions Dynamic

More information

Scan Conversion. Lines and Circles

Scan Conversion. Lines and Circles Scan Conversion Lines and Circles (Chapter 3 in Foley & Van Dam) 2D Line Implicit representation: αx + βy + γ = 0 Explicit representation: y y = mx+ B m= x Parametric representation: x P= y P = t y P +

More information

DC54 DATA STRUCTURES DEC 2014

DC54 DATA STRUCTURES DEC 2014 Q.2 a. Write a function that computes x^y using Recursion. The property that x^y is simply a product of x and x^(y-1 ). For example, 5^4= 5 * 5^3. The recursive definition of x^y can be represented as

More information

Total 100. The American University in Cairo Computer Science & Engineering Department CSCE 106. Dr. Khalil Exam II Fall 2011

Total 100. The American University in Cairo Computer Science & Engineering Department CSCE 106. Dr. Khalil Exam II Fall 2011 The American University in Cairo Computer Science & Engineering Department CSCE 106 Dr. Khalil Exam II Fall 2011 Last Name :... ID:... First Name:... Form I Section No.: ( ) EXAMINATION INSTRUCTIONS *

More information

POINTERS. Pointer is a memory variable which can store address of an object of specified data type. For example:

POINTERS. Pointer is a memory variable which can store address of an object of specified data type. For example: POINTERS Pointer is a memory variable which can store address of an object of specified data type For example: #include int x=5; int *a;//here a is a pointer to int which can store address of

More information

TEST BDA24202 / BTI10202 COMPUTER PROGRAMMING May 2013

TEST BDA24202 / BTI10202 COMPUTER PROGRAMMING May 2013 DEPARTMENT OF MATERIAL AND ENGINEERING DESIGN FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING UNIVERSITI TUN HUSSEIN ONN MALAYSIA (UTHM), JOHOR TEST BDA24202 / BTI10202 COMPUTER PROGRAMMING May 2013

More information

1. General Computer Questions

1. General Computer Questions CE 311K Introduction to Computer Methods McKinney Example Problems Section Page 1. General Computer Questions... 1 2. Flowcharts... 2 3. Number Systems... 3 5. Programming Language Facts... 4 1. General

More information

C Programming, Autumn 2013, Exercises for the Second Week

C Programming, Autumn 2013, Exercises for the Second Week C Programming, Autumn 2013, Exercises for the Second Week Notice: Remember that you can find information about a standard C library function by writing man 3 function_name in the terminal, or by going

More information

CSCE 110 Notes on Recursive Algorithms (Part 12) Prof. Amr Goneid

CSCE 110 Notes on Recursive Algorithms (Part 12) Prof. Amr Goneid CSCE 110 Notes on Recursive Algorithms (Part 12) Prof. Amr Goneid 1. Definition: The expression Recursion is derived from Latin: Re- = back and currere = to run, or to happen again, especially at repeated

More information

Computer Programming

Computer Programming Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering Session: Object-oriented Programming using Member Functions Dr. Deepak B. Phatak & Dr. Supratik

More information

The American University in Cairo Department of Computer Science & Engineeringt CSCI &09 Dr. KHALIL Exam-I Fall 2009

The American University in Cairo Department of Computer Science & Engineeringt CSCI &09 Dr. KHALIL Exam-I Fall 2009 The American University in Cairo Department of Computer Science & Engineeringt CSCI 106-05&09 Dr. KHALIL Exam-I Fall 2009 Last Name :... ID:... First Name:... Form I Section No.: EXAMINATION INSTRUCTIONS

More information

CSCE Practice Midterm. Data Types

CSCE Practice Midterm. Data Types CSCE 2004 - Practice Midterm This midterm exam was given in class several years ago. Work each of the following questions on your own. Once you are done, check your answers. For any questions whose answers

More information

FORM 2 (Please put your name and form # on the scantron!!!!)

FORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam 2: FORM 2 (Please put your name and form # on the scantron!!!!) True (A)/False(B) (2 pts each): 1. Recursive algorithms tend to be less efficient than iterative algorithms. 2. A recursive function

More information

Tokens, Expressions and Control Structures

Tokens, Expressions and Control Structures 3 Tokens, Expressions and Control Structures Tokens Keywords Identifiers Data types User-defined types Derived types Symbolic constants Declaration of variables Initialization Reference variables Type

More information

struct Properties C struct Types

struct Properties C struct Types struct Properties 1 The C struct mechanism is vaguely similar to the Java/C++ class mechanisms: - supports the creation of user-defined data types - struct types encapsulate data members struct Location

More information

Question7.How many proper subsets in all are there if a set contains (a) 7 elements (b) 4 elements

Question7.How many proper subsets in all are there if a set contains (a) 7 elements (b) 4 elements Question1. Write the following sets in roster form: 1. A={z: z=3x-8, x W and x0 and x is a multiple of 3 less than 100} Question2. Write the following

More information

advanced data types (2) typedef. today advanced data types (3) enum. mon 23 sep 2002 defining your own types using typedef

advanced data types (2) typedef. today advanced data types (3) enum. mon 23 sep 2002 defining your own types using typedef today advanced data types (1) typedef. mon 23 sep 2002 homework #1 due today homework #2 out today quiz #1 next class 30-45 minutes long one page of notes topics: C advanced data types dynamic memory allocation

More information

Chapter - 2: Geometry and Line Generations

Chapter - 2: Geometry and Line Generations Chapter - 2: Geometry and Line Generations In Computer graphics, various application ranges in different areas like entertainment to scientific image processing. In defining this all application mathematics

More information

Pointers. Mr. Ovass Shafi (Assistant Professor) Department of Computer Applications

Pointers. Mr. Ovass Shafi (Assistant Professor) Department of Computer Applications Pointers Introduction: A variable is a named memory location that holds some value. Each variable has some address associated with it. Till now we only worked on the values stored in the variables and

More information

Computational Geometry Lab: SEARCHING A TETRAHEDRAL MESH

Computational Geometry Lab: SEARCHING A TETRAHEDRAL MESH Computational Geometry Lab: SEARCHING A TETRAHEDRAL MESH John Burkardt Information Technology Department Virginia Tech http://people.sc.fsu.edu/ jburkardt/presentations/cg lab search tet mesh.pdf December

More information

C Programming Language: C ADTs, 2d Dynamic Allocation. Math 230 Assembly Language Programming (Computer Organization) Thursday Jan 31, 2008

C Programming Language: C ADTs, 2d Dynamic Allocation. Math 230 Assembly Language Programming (Computer Organization) Thursday Jan 31, 2008 C Programming Language: C ADTs, 2d Dynamic Allocation Math 230 Assembly Language Programming (Computer Organization) Thursday Jan 31, 2008 Overview Row major format 1 and 2-d dynamic allocation struct

More information

The Math Class. Using various math class methods. Formatting the values.

The Math Class. Using various math class methods. Formatting the values. The Math Class Using various math class methods. Formatting the values. The Math class is used for mathematical operations; in our case some of its functions will be used. In order to use the Math class,

More information

Recap. ANSI C Reserved Words C++ Multimedia Programming Lecture 2. Erwin M. Bakker Joachim Rijsdam

Recap. ANSI C Reserved Words C++ Multimedia Programming Lecture 2. Erwin M. Bakker Joachim Rijsdam Multimedia Programming 2004 Lecture 2 Erwin M. Bakker Joachim Rijsdam Recap Learning C++ by example No groups: everybody should experience developing and programming in C++! Assignments will determine

More information

Lab 2: Pointers. //declare a pointer variable ptr1 pointing to x. //change the value of x to 10 through ptr1

Lab 2: Pointers. //declare a pointer variable ptr1 pointing to x. //change the value of x to 10 through ptr1 Lab 2: Pointers 1. Goals Further understanding of pointer variables Passing parameters to functions by address (pointers) and by references Creating and using dynamic arrays Combing pointers, structures

More information

Types, Operators and Expressions

Types, Operators and Expressions Types, Operators and Expressions CSE 2031 Fall 2011 9/11/2011 5:24 PM 1 Variable Names (2.1) Combinations of letters, numbers, and underscore character ( _ ) that do not start with a number; are not a

More information

Type Definition. C Types. Derived. Function Array Pointer Structure Union Enumerated. EE 1910 Winter 2017/18

Type Definition. C Types. Derived. Function Array Pointer Structure Union Enumerated. EE 1910 Winter 2017/18 Enum and Struct Type Definition C Types Derived Function Array Pointer Structure Union Enumerated 2 tj Type Definition Typedef Define a new Type Inherits members and operations from a standard or previously

More information

Programming Studio #9 ECE 190

Programming Studio #9 ECE 190 Programming Studio #9 ECE 190 Programming Studio #9 Concepts: Functions review 2D Arrays GDB Announcements EXAM 3 CONFLICT REQUESTS, ON COMPASS, DUE THIS MONDAY 5PM. NO EXTENSIONS, NO EXCEPTIONS. Functions

More information

https://lambda.mines.edu 1 Recursion is a beautiful way to express many algorithms, as it typically makes our algorithm easier to prove. 2 Calling a function requires space on the call stack for the variables,

More information

(X 2,Y 2 ) (X 1,Y 1 ) (X 0,Y 0 ) (X c,y c ) (X 3,Y 3 )

(X 2,Y 2 ) (X 1,Y 1 ) (X 0,Y 0 ) (X c,y c ) (X 3,Y 3 ) Application Note Nov-2004 Probing for Dimensional Analysis This example shows how you can use Turbo PMAC s move-until-trigger function with the super-fast hardware position capture to find the exact location

More information

Review Problems for Final Exam. 1. What is the output of the following program? #include <iostream> #include <string> using namespace std;

Review Problems for Final Exam. 1. What is the output of the following program? #include <iostream> #include <string> using namespace std; Review Problems for Final Exam 1. What is the output of the following program? int draw(int n); int n = 4; while (n>0) n = draw(n); int draw(int n) for(int i = 0; i < n; i++) cout

More information

Chapter 7 Arithmetic

Chapter 7 Arithmetic Chapter 7 Arithmetic 7-1 Arithmetic in C++ Arithmetic expressions are made up of constants, variables, operators and parentheses. The arithmetic operators in C++ are as follows + (addition) - (subtraction)

More information

Arrays in C. Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. Indian Institute of Technology Kharagpur. Basic Concept

Arrays in C. Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. Indian Institute of Technology Kharagpur. Basic Concept Arrays in C Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. Indian Institute of Technology Kharagpur 1 Basic Concept Many applications require multiple data items that have common characteristics.

More information

Types, Operators and Expressions

Types, Operators and Expressions Types, Operators and Expressions EECS 2031 18 September 2017 1 Variable Names (2.1) l Combinations of letters, numbers, and underscore character ( _ ) that do not start with a number; are not a keyword.

More information

C++ ARRAYS POINTERS POINTER ARITHMETIC. Problem Solving with Computers-I

C++ ARRAYS POINTERS POINTER ARITHMETIC. Problem Solving with Computers-I C++ ARRAYS POINTERS POINTER ARITHMETIC Problem Solving with Computers-I General model of memory Sequence of adjacent cells Each cell has 1-byte stored in it Each cell has an address (memory location) Memory

More information

C Language Advanced Concepts. Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff

C Language Advanced Concepts. Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff C Language Advanced Concepts 1 Switch Statement Syntax Example switch (expression) { } case const_expr1: statement1; case const_expr2: : statement2; default: statementn; The break statement causes control

More information

Arrays. CS10001: Programming & Data Structures. Pallab Dasgupta Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur

Arrays. CS10001: Programming & Data Structures. Pallab Dasgupta Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur Arrays CS10001: Programming & Data Structures Pallab Dasgupta Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur 1 Array Many applications require multiple data items that have common

More information

C Multiple Choice Questions and answers MCQ with Ans.

C Multiple Choice Questions and answers MCQ with Ans. C Multiple Choice Questions and answers MCQ with Ans. 1. Who is father of C Language? A. Bjarne Stroustrup B. Dennis Ritchie C. James A. Gosling D. Dr. E.F. Codd Answer : B 2. C Language developed at?

More information

CS-211 Fall 2017 Test 1 Version Practice For Test on Oct. 2, Name:

CS-211 Fall 2017 Test 1 Version Practice For Test on Oct. 2, Name: CS-211 Fall 2017 Test 1 Version Practice For Test on Oct. 2, 2017 True/False Questions... Name: 1. (10 points) For the following, Check T if the statement is true, the F if the statement is false. (a)

More information

Final exam. Final exam will be 12 problems, drop any 2. Cumulative up to and including week 14 (emphasis on weeks 9-14: classes & pointers)

Final exam. Final exam will be 12 problems, drop any 2. Cumulative up to and including week 14 (emphasis on weeks 9-14: classes & pointers) Review Final exam Final exam will be 12 problems, drop any 2 Cumulative up to and including week 14 (emphasis on weeks 9-14: classes & pointers) 2 hours exam time, so 12 min per problem (midterm 2 had

More information

Haske k ll An introduction to Functional functional programming using Haskell Purely Lazy Example: QuickSort in Java Example: QuickSort in Haskell

Haske k ll An introduction to Functional functional programming using Haskell Purely Lazy Example: QuickSort in Java Example: QuickSort in Haskell Haskell An introduction to functional programming using Haskell Anders Møller amoeller@cs.au.dk The most popular purely functional, lazy programming language Functional programming language : a program

More information

ECE 3331, Dr. Hebert, Summer-3, 2016 HW 11 Hardcopy HW due Tues 07/19 Program due Sunday 07/17. Problem 1. Section 10.6, Exercise 3.

ECE 3331, Dr. Hebert, Summer-3, 2016 HW 11 Hardcopy HW due Tues 07/19 Program due Sunday 07/17. Problem 1. Section 10.6, Exercise 3. ECE 3331, Dr. Hebert, Summer-3, 2016 HW 11 Hardcopy HW due Tues 07/19 Program due Sunday 07/17 Problem 1. Section 10.6, Exercise 3. Problem 2. Section 10.6, Exercise 5. Problem 3. Section 10.6, Exercise

More information

CSCE 110 PROGRAMMING FUNDAMENTALS. Prof. Amr Goneid AUC

CSCE 110 PROGRAMMING FUNDAMENTALS. Prof. Amr Goneid AUC CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 13. Abstract Data Types (ADT s) Prof. amr Goneid, AUC 1 Data Modeling and ADTs Prof. Amr Goneid, AUC 2 Data Modeling and ADTs Data Modeling

More information