CMPT 130 Sample Final Solution
|
|
- Lindsay Booker
- 7 years ago
- Views:
Transcription
1 CMPT 130 Sample Final Solution Last name exactly as it appears on your student card First name exactly as it appears on your student card Student Number SFU This is a 180 minute test. It is closed book: no calculators, computers, notes, books, etc. are allowed. Question Your mark Out of What's Printed 20 Multiple Choice 5 Memory 7 Fragments 9 Structures 10 Perfect Numbers 8 Binary to Decimal 8 Total Page 1 of 10
2 Question 1: What s Printed? Show what would be printed by each of the statements shown below. int i; for(i = 0; i < 4; ++i) printf("%d ", i+1); The next 7 questions are related to each other int arr1[] = 2,4,6,8,10; int* p = arr1; int s = 0; int* q; printf("\n%d\n", sizeof(arr1)); 1,2,3,4 20 printf("%d\n", sizeof(p)); 4 printf("%d\n", sizeof(*p)); 4 printf("%d\n", *p); 2 printf("%d\n", arr1[3]); 8 for(q = arr1; q < arr1 + 5; s += *q++); printf("%d\n", q-p); 5 printf("%d\n", s); 30 long long yy = 0; int x = 412; printf("%d\n%d\n", yy, x); 0 0 int hex = 163; printf("%x\n", hex); a3 Page 2 of 10
3 The next 8 questions are related to each other char str1[15] = "hades"; char str2[15] = "haddock"; printf("%d\n", sizeof(str1)); 15 printf("%d\n", strlen(str1)); 5 putchar(str1[3]); e printf("\n%d\n", str1[6]); 0 fputs(str2, stdout); if(strncmp(str1, str2, 3) == 0) printf("\nsame\n"); else printf("different\n"); printf(strcat(str1, ", pluto")); haddock same hades, pluto printf("\n%d\n",str1[2] - str1[1]); 3 if(7 < 5 3 && 3!= 4) printf("true\n"); else printf("false\n"); int start = 0; int end = 0; while(start < 100) start++; if(start % 2 == 1) continue; if(start == 8) break; end++; printf("%d\n", end); true 3 Page 3 of 10
4 Question 2: Multiple Choice Which of the following are likely to result in a stack overflow? 1. A recursive function with no base case 2. An infinite loop that does not contain variable declarations 3. Allocating space in automatic memory for many large structures 4. Allocating space in dynamic memory for many large structures a. 1 and 3 b. 1, 2 and 3 c. 1 only d. 1, 2, 3 and 4 Which of the following correctly allocates spaces in dynamic memory for an array of 100 doubles? a. double* p = malloc(100, sizeof(double)); b. double* p = malloc(100 * sizeof(double)); c. double* p = malloc(100 * sizeof(int)); d. double* p = calloc(100 * sizeof(double)); a Which of the following placeholders would be appropriate for displaying right justified, positive floating point numbers less than one million to three decimal places. Assume that a column of such numbers is to be displayed so that they line up. a. "%-6.3f" b. "%6.3f" c. "%-10.3f" d. "%10.3f" What is printed by the call to f shown below? printf("f(5) = %d", f(5)); a. f(5) = 5 b. f(5) = 32 c. nothing, f does not compile d. f(5) = 10 int f(int x) if(x > 1) return 2 * f(x - 1); else if(x == 1) return 2; else return x; Which of the following is the best description of the error in the statements shown below: b d b int arr[] = 1,2,3,4; arr = int[10]; a. The variable arr is declared twice b. An array cannot be initialized with a bracketed list of values c. An array variable must be specified with a constant or a literal d. A previously declared array variable cannot be assigned another array d Page 4 of 10
5 Question 3: Memory #include "stdio.h" #include "stdlib.h" int num = 33; int glob = 42; static int fill = 113; int bar(int* aa, int bb); int main() int i; int num = 10; int x = 100; int* arr = calloc(num, sizeof(int)); for(i = 0; i < num; ++i) int x; x = i * 2; arr[i] = x; printf("%d\n", bar(&num, x)); printf("%d\n", bar(&num, x)); printf("%d, %d\n", bar(&x, x), num); free(arr); return 0; int bar(int* a, int b) static int count = 0; ++(*a); b++; count++; return count; For each variable state the line numbers corresponding to its scope. Example line 05 glob 05 to 38 line 06 fill line 08 aa 08 line 13 num line 14 x 14-16, line 18 x State the variables' storage locations. Select static, automatic or dynamic. line 05 glob line 15 arr static line 15 - data assigned to arr line 33 count line 31 b automatic static automatic dynamic What is printed by the last print statement (line 25)? 3, 10 Is the linkage of fill (line 06) internal or external? internal or external. internal (because of static) Page 5 of 10
6 Question 4: Fragments Complete the program fragment shown to the right by writing a while loop that repeatedly prompts the user to guess a number. The loop should terminate when the guess is equal to the answer. Sample Output Guess the number! 12 Guess the number! 6 Guess the number! 19 Guess the number! 4 Guess the number! 17 Congratulations! Complete the program fragment shown to the right by writing a for loop that prints all of the integers between start and end, with each integer printed on a separate line. If start is greater than end nothing should be printed. Sample Output Enter the start value: -2 Enter the end value: Complete the program fragment shown to the right by writing an if statement that checks to see if the three variables are all equal to each other, all are different, or if just two are equal. Sample Output (3 different executions) Enter three numbers: they are all different Enter three numbers: they are all the same Enter three numbers: only two are the same int answer = rand()%20; int guess = 0; while(answer!= guess) printf("guess the number! "); scanf("%d", &guess); printf("congratulations!\n"); int i, start, end; printf("enter the start value: "); scanf("%d", &start); printf("enter the end value: "); scanf("%d", &end); for(i = start; i <= end; ++i) printf("%+2d\n", i); int x, y, z; printf("enter three numbers: "); scanf("%d%d%d", &x, &y,&z); if(x == y && x == z) printf("they are all the same\n"); else if(x!= y && x!= z && y!= z) printf("they are all different\n"); else printf("only two are the same\n"); Page 6 of 10
7 Question 5: Structures #include "stdio.h" #include "stdlib.h" #define FNAME_LEN 20 #define NAME_LEN 10 #define MAX_AC 10 typedef struct char name[name_len]; float balance; account; account foo(account* pacc, int size); int main() char fname[fname_len]; account bank[max_ac]; FILE* fp; int readresult = 2; int size = 0; account smacc; account test = "bob", ; account* pacc = &test; printf("enter a file name: "); gets(fname); if((fp = fopen(fname, "r")) == NULL) printf("error 1"); exit(1); readresult = fscanf(fp, "%s%f", bank[size].name, &bank[size].balance); if(readresult!= 2) printf("error 2"); exit(1); while(readresult == 2) size++; readresult = fscanf(fp, "%s%f", bank[size].name, &bank[size].balance); printf("%s\n", test.name); printf("%.2f\n", pacc->balance); printf("%s\n", bank[0].name); printf("%c\n", bank->name[0]); account foo(account* pacc, int size) int i; account result = pacc[0]; for(i = 1; i < size; ++i) if(pacc[i].balance < result.balance) result = pacc[i]; return result; smacc = foo(bank, size); printf("name = %s, balance = %.0f\n", smacc.name, smacc.balance); return 0; Page 7 of 10
8 The questions on this page (except the two multiple choice questions) relate to the program shown on page 7. Show what is printed by the program for each of the three input files shown below. Note that there is no file called loans3.txt! contents of loans1.txt Bruce Diana Clark Peter Dinah Bob Sue Kate contents of loans2.txt no file called loans3.txt exists Enter a file name: loans1.txt bob Bruce B name = Peter, balance = 12 Enter a file name: loans2.txt error 2 Enter a file name: loans3.txt error 1 Which of the following statements will open a file called vip.txt without over-writing its data, and allow data to be added to the end of the file, and allow the contents of the file to be read? a. FILE* fp = fopen(fname, "w+"); b. FILE* fp = fopen(fname, "w"); c. FILE* fp = fopen(fname, "a+"); d. FILE* fp = fopen(fname, "w"); Which of the following function calls would write a double array of size 100 (called arr) to a binary file which is pointed to by the file pointer fp? a. fwrite(arr, sizeof(double), 100, fp); b. for(i=0; i < 100; ++i) fwrite(arr[i], sizeof(double), 100, fp); c. for(i=0; i < 100; ++i) fprintf(fp, "%f", arr[i]); d. fread(arr, sizeof(double), 100, fp); c a Page 8 of 10
9 Question 6: Perfect Number A perfect number is a positive number that is equal to the sum of its proper positive divisors (a proper divisor is a positive divisor of a number, excluding the number itself). For example 6 is a perfect number, since its divisors are 3, 2 and 1. Write a function with a single integer parameter that returns 1 if its parameter is a perfect number and 0 if it is not. Examples int isperfect = perfect(6); // isperfect = 1 isperfect = perfect(8); // isperfect = 0 int perfect(int x) int sum = 0; for(int i = 1; i < x; ++i) if(x % i == 0) sum += i; if(sum == x) return 1; else return 0; Page 9 of 10
10 Question 7: Binary to Decimal Write a function that takes a string representation of a binary number and returns the decimal equivalent. Your function should have a single character array parameter and should return an integer. Examples int bin = binarytodecimal("11111"); // bin = 31 bin = binarytodecimal("101010"); // bin = 42 bin = binarytodecimal("-100"); // bin = -4 int binarytodecimal(char bin[]) int result = 0; int power = 1; char ch; for(int i = strlen(bin)-1; i >= 0; i--) if(bin[i] == '1') result += power; power = power * 2; return result; Page 10 of 10
Senem Kumova Metin & Ilker Korkmaz 1
Senem Kumova Metin & Ilker Korkmaz 1 A loop is a block of code that can be performed repeatedly. A loop is controlled by a condition that is checked each time through the loop. C supports two categories
More information7th Marathon of Parallel Programming WSCAD-SSC/SBAC-PAD-2012
7th Marathon of Parallel Programming WSCAD-SSC/SBAC-PAD-2012 October 17 th, 2012. Rules For all problems, read carefully the input and output session. For all problems, a sequential implementation is given,
More informationStacks. Linear data structures
Stacks Linear data structures Collection of components that can be arranged as a straight line Data structure grows or shrinks as we add or remove objects ADTs provide an abstract layer for various operations
More informationModule 816. File Management in C. M. Campbell 1993 Deakin University
M. Campbell 1993 Deakin University Aim Learning objectives Content After working through this module you should be able to create C programs that create an use both text and binary files. After working
More informationIntroduction to Java
Introduction to Java The HelloWorld program Primitive data types Assignment and arithmetic operations User input Conditional statements Looping Arrays CSA0011 Matthew Xuereb 2008 1 Java Overview A high
More informationLecture 11 Doubly Linked Lists & Array of Linked Lists. Doubly Linked Lists
Lecture 11 Doubly Linked Lists & Array of Linked Lists In this lecture Doubly linked lists Array of Linked Lists Creating an Array of Linked Lists Representing a Sparse Matrix Defining a Node for a Sparse
More informationIllustration 1: Diagram of program function and data flow
The contract called for creation of a random access database of plumbing shops within the near perimeter of FIU Engineering school. The database features a rating number from 1-10 to offer a guideline
More information1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++
Answer the following 1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++ 2) Which data structure is needed to convert infix notations to postfix notations? Stack 3) The
More informationMemory management. Announcements. Safe user input. Function pointers. Uses of function pointers. Function pointer example
Announcements Memory management Assignment 2 posted, due Friday Do two of the three problems Assignment 1 graded see grades on CMS Lecture 7 CS 113 Spring 2008 2 Safe user input If you use scanf(), include
More informationThe C Programming Language course syllabus associate level
TECHNOLOGIES The C Programming Language course syllabus associate level Course description The course fully covers the basics of programming in the C programming language and demonstrates fundamental programming
More information1. Relational database accesses data in a sequential form. (Figures 7.1, 7.2)
Chapter 7 Data Structures for Computer Graphics (This chapter was written for programmers - option in lecture course) Any computer model of an Object must comprise three different types of entities: 1.
More informationIntroduction to Lex. General Description Input file Output file How matching is done Regular expressions Local names Using Lex
Introduction to Lex General Description Input file Output file How matching is done Regular expressions Local names Using Lex General Description Lex is a program that automatically generates code for
More informationC Programming. Charudatt Kadolkar. IIT Guwahati. C Programming p.1/34
C Programming Charudatt Kadolkar IIT Guwahati C Programming p.1/34 We want to print a table of sine function. The output should look like: 0 0.0000 20 0.3420 40 0.6428 60 0.8660 80 0.9848 100 0.9848 120
More information1 Abstract Data Types Information Hiding
1 1 Abstract Data Types Information Hiding 1.1 Data Types Data types are an integral part of every programming language. ANSI-C has int, double and char to name just a few. Programmers are rarely content
More informationSystem Calls and Standard I/O
System Calls and Standard I/O Professor Jennifer Rexford http://www.cs.princeton.edu/~jrex 1 Goals of Today s Class System calls o How a user process contacts the Operating System o For advanced services
More informationNumber Representation
Number Representation CS10001: Programming & Data Structures Pallab Dasgupta Professor, Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur Topics to be Discussed How are numeric data
More informationMULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.
Exam Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) The JDK command to compile a class in the file Test.java is A) java Test.java B) java
More informationSources: On the Web: Slides will be available on:
C programming Introduction The basics of algorithms Structure of a C code, compilation step Constant, variable type, variable scope Expression and operators: assignment, arithmetic operators, comparison,
More informationUnit 1. 5. Write iterative and recursive C functions to find the greatest common divisor of two integers. [6]
Unit 1 1. Write the following statements in C : [4] Print the address of a float variable P. Declare and initialize an array to four characters a,b,c,d. 2. Declare a pointer to a function f which accepts
More informationMolecular Dynamics Simulations with Applications in Soft Matter Handout 7 Memory Diagram of a Struct
Dr. Martin O. Steinhauser University of Basel Graduate Lecture Spring Semester 2014 Molecular Dynamics Simulations with Applications in Soft Matter Handout 7 Memory Diagram of a Struct Friday, 7 th March
More informationAnswers to Review Questions Chapter 7
Answers to Review Questions Chapter 7 1. The size declarator is used in a definition of an array to indicate the number of elements the array will have. A subscript is used to access a specific element
More informationInformatica e Sistemi in Tempo Reale
Informatica e Sistemi in Tempo Reale Introduction to C programming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 25, 2010 G. Lipari (Scuola Superiore Sant Anna)
More informationMAX = 5 Current = 0 'This will declare an array with 5 elements. Inserting a Value onto the Stack (Push) -----------------------------------------
=============================================================================================================================== DATA STRUCTURE PSEUDO-CODE EXAMPLES (c) Mubashir N. Mir - www.mubashirnabi.com
More informationEmbedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C
Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C 1 An essential part of any embedded system design Programming 2 Programming in Assembly or HLL Processor and memory-sensitive
More informationLecture 3. Arrays. Name of array. c[0] c[1] c[2] c[3] c[4] c[5] c[6] c[7] c[8] c[9] c[10] c[11] Position number of the element within array c
Lecture 3 Data structures arrays structs C strings: array of chars Arrays as parameters to functions Multiple subscripted arrays Structs as parameters to functions Default arguments Inline functions Redirection
More informationPassing 1D arrays to functions.
Passing 1D arrays to functions. In C++ arrays can only be reference parameters. It is not possible to pass an array by value. Therefore, the ampersand (&) is omitted. What is actually passed to the function,
More information10CS35: Data Structures Using C
CS35: Data Structures Using C QUESTION BANK REVIEW OF STRUCTURES AND POINTERS, INTRODUCTION TO SPECIAL FEATURES OF C OBJECTIVE: Learn : Usage of structures, unions - a conventional tool for handling a
More informationKeywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void
1. Explain C tokens Tokens are basic building blocks of a C program. A token is the smallest element of a C program that is meaningful to the compiler. The C compiler recognizes the following kinds of
More informationChapter 2: Elements of Java
Chapter 2: Elements of Java Basic components of a Java program Primitive data types Arithmetic expressions Type casting. The String type (introduction) Basic I/O statements Importing packages. 1 Introduction
More informationOutput: 12 18 30 72 90 87. struct treenode{ int data; struct treenode *left, *right; } struct treenode *tree_ptr;
50 20 70 10 30 69 90 14 35 68 85 98 16 22 60 34 (c) Execute the algorithm shown below using the tree shown above. Show the exact output produced by the algorithm. Assume that the initial call is: prob3(root)
More information/* File: blkcopy.c. size_t n
13.1. BLOCK INPUT/OUTPUT 505 /* File: blkcopy.c The program uses block I/O to copy a file. */ #include main() { signed char buf[100] const void *ptr = (void *) buf FILE *input, *output size_t
More informationFEEG6002 - Applied Programming 5 - Tutorial Session
FEEG6002 - Applied Programming 5 - Tutorial Session Sam Sinayoko 2015-10-30 1 / 38 Outline Objectives Two common bugs General comments on style String formatting Questions? Summary 2 / 38 Objectives Revise
More informationDNA Data and Program Representation. Alexandre David 1.2.05 adavid@cs.aau.dk
DNA Data and Program Representation Alexandre David 1.2.05 adavid@cs.aau.dk Introduction Very important to understand how data is represented. operations limits precision Digital logic built on 2-valued
More informationEmbedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C
Embedded Systems A Review of ANSI C and Considerations for Embedded C Programming Dr. Jeff Jackson Lecture 2-1 Review of ANSI C Topics Basic features of C C fundamentals Basic data types Expressions Selection
More informationC Interview Questions
http://techpreparation.com C Interview Questions And Answers 2008 V i s i t T e c h P r e p a r a t i o n. c o m f o r m o r e i n t e r v i e w q u e s t i o n s a n d a n s w e r s C Interview Questions
More informationArrays in Java. Working with Arrays
Arrays in Java So far we have talked about variables as a storage location for a single value of a particular data type. We can also define a variable in such a way that it can store multiple values. Such
More informationShort Notes on Dynamic Memory Allocation, Pointer and Data Structure
Short Notes on Dynamic Memory Allocation, Pointer and Data Structure 1 Dynamic Memory Allocation in C/C++ Motivation /* a[100] vs. *b or *c */ Func(int array_size) double k, a[100], *b, *c; b = (double
More informationStack Allocation. Run-Time Data Structures. Static Structures
Run-Time Data Structures Stack Allocation Static Structures For static structures, a fixed address is used throughout execution. This is the oldest and simplest memory organization. In current compilers,
More informationChapter 13 Storage classes
Chapter 13 Storage classes 1. Storage classes 2. Storage Class auto 3. Storage Class extern 4. Storage Class static 5. Storage Class register 6. Global and Local Variables 7. Nested Blocks with the Same
More informationC++FA 5.1 PRACTICE MID-TERM EXAM
C++FA 5.1 PRACTICE MID-TERM EXAM This practicemid-term exam covers sections C++FA 1.1 through C++FA 1.4 of C++ with Financial Applications by Ben Van Vliet, available at www.benvanvliet.net. 1.) A pointer
More informationJ a v a Quiz (Unit 3, Test 0 Practice)
Computer Science S-111a: Intensive Introduction to Computer Science Using Java Handout #11 Your Name Teaching Fellow J a v a Quiz (Unit 3, Test 0 Practice) Multiple-choice questions are worth 2 points
More informationName: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.
Name: Class: Date: Exam #1 - Prep True/False Indicate whether the statement is true or false. 1. Programming is the process of writing a computer program in a language that the computer can respond to
More informationThe Advantages of Dan Grossman CSE303 Spring 2005, Lecture 25
CSE 303: Concepts and Tools for Software Development Dan Grossman Spring 2005 Lecture 25 Memory-Management Idioms Dan Grossman CSE303 Spring 2005, Lecture 25 1 No tools or rule today Review: Java and C
More informationC Programming. for Embedded Microcontrollers. Warwick A. Smith. Postbus 11. Elektor International Media BV. 6114ZG Susteren The Netherlands
C Programming for Embedded Microcontrollers Warwick A. Smith Elektor International Media BV Postbus 11 6114ZG Susteren The Netherlands 3 the Table of Contents Introduction 11 Target Audience 11 What is
More informationAn Introduction to Assembly Programming with the ARM 32-bit Processor Family
An Introduction to Assembly Programming with the ARM 32-bit Processor Family G. Agosta Politecnico di Milano December 3, 2011 Contents 1 Introduction 1 1.1 Prerequisites............................. 2
More informationExample 1/24. Example
Example CandC++. Misc. Library Features Gotchas Hints n Tips int **ppi int *pi int i char *pc char c Stephen Clark 5 University of Cambridge (heavily based on last year s notes (Andrew Moore) with thanks
More informationQuiz 4 Solutions EECS 211: FUNDAMENTALS OF COMPUTER PROGRAMMING II. 1 Q u i z 4 S o l u t i o n s
Quiz 4 Solutions Q1: What value does function mystery return when called with a value of 4? int mystery ( int number ) { if ( number
More informationCOMPUTER SCIENCE. Paper 1 (THEORY)
COMPUTER SCIENCE Paper 1 (THEORY) (Three hours) Maximum Marks: 70 (Candidates are allowed additional 15 minutes for only reading the paper. They must NOT start writing during this time) -----------------------------------------------------------------------------------------------------------------------
More information(hours worked,rateofpay, and regular and over time pay) for a list of employees. We have
Chapter 9 Two Dimensional Arrays In Chapter 7 we have seen that C provides a compound data structure for storing a list of related data. For some applications, however, such a structure may not be sucient
More informationUIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming
UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming 1 2 Foreword First of all, this book isn t really for dummies. I wrote it for myself and other kids who are on the team. Everything
More informationData Structure with C
Subject: Data Structure with C Topic : Tree Tree A tree is a set of nodes that either:is empty or has a designated node, called the root, from which hierarchically descend zero or more subtrees, which
More informationThe programming language C. sws1 1
The programming language C sws1 1 The programming language C invented by Dennis Ritchie in early 1970s who used it to write the first Hello World program C was used to write UNIX Standardised as K&C (Kernighan
More informationPseudo code Tutorial and Exercises Teacher s Version
Pseudo code Tutorial and Exercises Teacher s Version Pseudo-code is an informal way to express the design of a computer program or an algorithm in 1.45. The aim is to get the idea quickly and also easy
More informationWhat Is Recursion? Recursion. Binary search example postponed to end of lecture
Recursion Binary search example postponed to end of lecture What Is Recursion? Recursive call A method call in which the method being called is the same as the one making the call Direct recursion Recursion
More informationCOMP 250 Fall 2012 lecture 2 binary representations Sept. 11, 2012
Binary numbers The reason humans represent numbers using decimal (the ten digits from 0,1,... 9) is that we have ten fingers. There is no other reason than that. There is nothing special otherwise about
More informationIntroduction to Java Applications. 2005 Pearson Education, Inc. All rights reserved.
1 2 Introduction to Java Applications 2.2 First Program in Java: Printing a Line of Text 2 Application Executes when you use the java command to launch the Java Virtual Machine (JVM) Sample program Displays
More informationCP Lab 2: Writing programs for simple arithmetic problems
Computer Programming (CP) Lab 2, 2015/16 1 CP Lab 2: Writing programs for simple arithmetic problems Instructions The purpose of this Lab is to guide you through a series of simple programming problems,
More informationObject-Oriented Programming in Java
CSCI/CMPE 3326 Object-Oriented Programming in Java Class, object, member field and method, final constant, format specifier, file I/O Dongchul Kim Department of Computer Science University of Texas Rio
More information3. Convert a number from one number system to another
3. Convert a number from one number system to another Conversion between number bases: Hexa (16) Decimal (10) Binary (2) Octal (8) More Interest Way we need conversion? We need decimal system for real
More informationTail call elimination. Michel Schinz
Tail call elimination Michel Schinz Tail calls and their elimination Loops in functional languages Several functional programming languages do not have an explicit looping statement. Instead, programmers
More informationClient-server Sockets
Client-server Sockets 1 How to Write a Network Based Program (Using Microchip's TCP/IP Stack) A network based program that uses the Client-server architecture must create at least two separate programs,
More informationWe will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.
LING115 Lecture Note Session #4 Python (1) 1. Introduction As we have seen in previous sessions, we can use Linux shell commands to do simple text processing. We now know, for example, how to count words.
More informationA single register, called the accumulator, stores the. operand before the operation, and stores the result. Add y # add y from memory to the acc
Other architectures Example. Accumulator-based machines A single register, called the accumulator, stores the operand before the operation, and stores the result after the operation. Load x # into acc
More informationFunctions Recursion. C++ functions. Declare/prototype. Define. Call. int myfunction (int ); int myfunction (int x){ int y = x*x; return y; }
Functions Recursion C++ functions Declare/prototype int myfunction (int ); Define int myfunction (int x){ int y = x*x; return y; Call int a; a = myfunction (7); function call flow types type of function
More informationHow To Write Portable Programs In C
Writing Portable Programs COS 217 1 Goals of Today s Class Writing portable programs in C Sources of heterogeneity Data types, evaluation order, byte order, char set, Reading period and final exam Important
More informationCS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013
Oct 4, 2013, p 1 Name: CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 1. (max 18) 4. (max 16) 2. (max 12) 5. (max 12) 3. (max 24) 6. (max 18) Total: (max 100)
More informationStorage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas
CS 110B - Rule Storage Classes Page 18-1 Attributes are distinctive features of a variable. Data type, int or double for example, is an attribute. Storage class is another attribute. There are four storage
More informationTutorial on C Language Programming
Tutorial on C Language Programming Teodor Rus rus@cs.uiowa.edu The University of Iowa, Department of Computer Science Introduction to System Software p.1/64 Tutorial on C programming C program structure:
More informationAs previously noted, a byte can contain a numeric value in the range 0-255. Computers don't understand Latin, Cyrillic, Hindi, Arabic character sets!
Encoding of alphanumeric and special characters As previously noted, a byte can contain a numeric value in the range 0-255. Computers don't understand Latin, Cyrillic, Hindi, Arabic character sets! Alphanumeric
More informationMasters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013
Masters programmes in Computer Science and Information Systems Object-Oriented Design and Programming Sample module entry test xxth December 2013 This sample paper has more questions than the real paper
More informationarrays C Programming Language - Arrays
arrays So far, we have been using only scalar variables scalar meaning a variable with a single value But many things require a set of related values coordinates or vectors require 3 (or 2, or 4, or more)
More informationThe Tower of Hanoi. Recursion Solution. Recursive Function. Time Complexity. Recursive Thinking. Why Recursion? n! = n* (n-1)!
The Tower of Hanoi Recursion Solution recursion recursion recursion Recursive Thinking: ignore everything but the bottom disk. 1 2 Recursive Function Time Complexity Hanoi (n, src, dest, temp): If (n >
More informationThe University of Alabama in Huntsville Electrical and Computer Engineering CPE 112 01 Test #4 November 20, 2002. True or False (2 points each)
True or False (2 points each) The University of Alabama in Huntsville Electrical and Computer Engineering CPE 112 01 Test #4 November 20, 2002 1. Using global variables is better style than using local
More informationIntroduction to Data Structures
Introduction to Data Structures Albert Gural October 28, 2011 1 Introduction When trying to convert from an algorithm to the actual code, one important aspect to consider is how to store and manipulate
More informationLecture 22: C Programming 4 Embedded Systems
Lecture 22: C Programming 4 Embedded Systems Today s Goals Basic C programming process Variables and constants in C Pointers to access addresses Using a High Level Language High-level languages More human
More informationIntroduction to Programming (in C++) Loops. Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC
Introduction to Programming (in C++) Loops Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC Example Assume the following specification: Input: read a number N > 0 Output:
More informationExample. Introduction to Programming (in C++) Loops. The while statement. Write the numbers 1 N. Assume the following specification:
Example Introduction to Programming (in C++) Loops Assume the following specification: Input: read a number N > 0 Output: write the sequence 1 2 3 N (one number per line) Jordi Cortadella, Ricard Gavaldà,
More informationCSC4510 AUTOMATA 2.1 Finite Automata: Examples and D efinitions Definitions
CSC45 AUTOMATA 2. Finite Automata: Examples and Definitions Finite Automata: Examples and Definitions A finite automaton is a simple type of computer. Itsoutputislimitedto yes to or no. It has very primitive
More informationData Structures. Algorithm Performance and Big O Analysis
Data Structures Algorithm Performance and Big O Analysis What s an Algorithm? a clearly specified set of instructions to be followed to solve a problem. In essence: A computer program. In detail: Defined
More informationRegression Verification: Status Report
Regression Verification: Status Report Presentation by Dennis Felsing within the Projektgruppe Formale Methoden der Softwareentwicklung 2013-12-11 1/22 Introduction How to prevent regressions in software
More informationASCII Encoding. The char Type. Manipulating Characters. Manipulating Characters
The char Type ASCII Encoding The C char type stores small integers. It is usually 8 bits. char variables guaranteed to be able to hold integers 0.. +127. char variables mostly used to store characters
More informationThe following themes form the major topics of this chapter: The terms and concepts related to trees (Section 5.2).
CHAPTER 5 The Tree Data Model There are many situations in which information has a hierarchical or nested structure like that found in family trees or organization charts. The abstraction that models hierarchical
More informationPART-A Questions. 2. How does an enumerated statement differ from a typedef statement?
1. Distinguish & and && operators. PART-A Questions 2. How does an enumerated statement differ from a typedef statement? 3. What are the various members of a class? 4. Who can access the protected members
More informationComputer Science 2nd Year Solved Exercise. Programs 3/4/2013. Aumir Shabbir Pakistan School & College Muscat. Important. Chapter # 3.
2013 Computer Science 2nd Year Solved Exercise Chapter # 3 Programs Chapter # 4 Chapter # 5 Chapter # 6 Chapter # 7 Important Work Sheets Aumir Shabbir Pakistan School & College Muscat 3/4/2013 Chap #
More informationObject Oriented Software Design II
Object Oriented Software Design II Introduction to C++ Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 20, 2012 G. Lipari (Scuola Superiore Sant Anna) C++ Intro February
More informationSoftware security. Buffer overflow attacks SQL injections. Lecture 11 EIT060 Computer Security
Software security Buffer overflow attacks SQL injections Lecture 11 EIT060 Computer Security Buffer overflow attacks Buffer overrun is another common term Definition A condition at an interface under which
More informationFile Handling. What is a file?
File Handling 1 What is a file? A named collection of data, stored in secondary storage (typically). Typical operations on files: Open Read Write Close How is a file stored? Stored as sequence of bytes,
More informationBoolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)
Boolean Expressions, Conditions, Loops, and Enumerations Relational Operators == // true if two values are equivalent!= // true if two values are not equivalent < // true if left value is less than the
More informationExample of a Java program
Example of a Java program class SomeNumbers static int square (int x) return x*x; public static void main (String[] args) int n=20; if (args.length > 0) // change default n = Integer.parseInt(args[0]);
More informationCoding Rules. Encoding the type of a function into the name (so-called Hungarian notation) is forbidden - it only confuses the programmer.
Coding Rules Section A: Linux kernel style based coding for C programs Coding style for C is based on Linux Kernel coding style. The following excerpts in this section are mostly taken as is from articles
More informationScoping (Readings 7.1,7.4,7.6) Parameter passing methods (7.5) Building symbol tables (7.6)
Semantic Analysis Scoping (Readings 7.1,7.4,7.6) Static Dynamic Parameter passing methods (7.5) Building symbol tables (7.6) How to use them to find multiply-declared and undeclared variables Type checking
More informationFree Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program
Free Java textbook available online "Thinking in Java" by Bruce Eckel, 4th edition, 2006, ISBN 0131872486, Pearson Education Introduction to the Java programming language CS 4354 Summer II 2014 Jill Seaman
More informationBasics of I/O Streams and File I/O
Basics of This is like a cheat sheet for file I/O in C++. It summarizes the steps you must take to do basic I/O to and from files, with only a tiny bit of explanation. It is not a replacement for reading
More informationIntroduction to Python
Caltech/LEAD Summer 2012 Computer Science Lecture 2: July 10, 2012 Introduction to Python The Python shell Outline Python as a calculator Arithmetic expressions Operator precedence Variables and assignment
More informationDisplaying a Numerical Value on HyperTerminal (or equ.)
(Here, only an integer value is discussed) Objective Sometimes, the result of a calculations or the value of a variable needs to be displayed on a terminal. Points to Consider A numerical value is stored
More informationWhat is a Loop? Pretest Loops in C++ Types of Loop Testing. Count-controlled loops. Loops can be...
What is a Loop? CSC Intermediate Programming Looping A loop is a repetition control structure It causes a single statement or a group of statements to be executed repeatedly It uses a condition to control
More informationHOMEWORK # 2 SOLUTIO
HOMEWORK # 2 SOLUTIO Problem 1 (2 points) a. There are 313 characters in the Tamil language. If every character is to be encoded into a unique bit pattern, what is the minimum number of bits required to
More informationVB.NET Programming Fundamentals
Chapter 3 Objectives Programming Fundamentals In this chapter, you will: Learn about the programming language Write a module definition Use variables and data types Compute with Write decision-making statements
More informationSystem.out.println("\nEnter Product Number 1-5 (0 to stop and view summary) :
Benjamin Michael Java Homework 3 10/31/2012 1) Sales.java Code // Sales.java // Program calculates sales, based on an input of product // number and quantity sold import java.util.scanner; public class
More information