UNIVERSITY OF LIMERICK OLLSCOIL LUIMNIGH COLLEGE OF INFORMATICS & ELECTRONICS DEPARTMENT OF ELECTRONIC & COMPUTER ENGINEERING

Similar documents
Informatics Ingeniería en Electrónica y Automática Industrial

3. EXPRESSIONS. It is a sequence of operands and operators that reduce to a single value.

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

Computers Programming Course 6. Iulian Năstac

Expression and Operator

Operators in C. Staff Incharge: S.Sasirekha

Fundamentals of Programming

Beginning C Programming for Engineers

Prepared by: Shraddha Modi

Fundamental of Programming (C)

CSE 351: The Hardware/Software Interface. Section 2 Integer representations, two s complement, and bitwise operators

First of all, it is a variable, just like other variables you studied

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

Guide for The C Programming Language Chapter 1. Q1. Explain the structure of a C program Answer: Structure of the C program is shown below:

UNIT- 3 Introduction to C++

A complex expression to evaluate we need to reduce it to a series of simple expressions. E.g * 7 =>2+ 35 => 37. E.g.

Function I/O. Function Input and Output. Input through actual parameters. Output through return value. Input/Output through side effects

Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur

GO - OPERATORS. This tutorial will explain the arithmetic, relational, logical, bitwise, assignment and other operators one by one.

Variables and Operators 2/20/01 Lecture #

Function I/O. Last Updated 10/30/18

Lesson #3. Variables, Operators, and Expressions. 3. Variables, Operators and Expressions - Copyright Denis Hamelin - Ryerson University

Expressions and Precedence. Last updated 12/10/18

Programming. Elementary Concepts

Unit-2 (Operators) ANAND KR.SRIVASTAVA

A flow chart is a graphical or symbolic representation of a process.

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

Sample Examination. Family Name:... Other Names:... Signature:... Student Number:...

UNIT 3 OPERATORS. [Marks- 12]

Operators. Java operators are classified into three categories:

Infix to Postfix Conversion

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9

CS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation

CSE 30 Winter 2014 Final Exam

Chapter 4: Basic C Operators

CS 241 Data Organization Binary

Computer Organization & Systems Exam I Example Questions

Department of Computer Science

Expressions and Statementst t. Assignment Operator. C Programming Lecture 6 : Operators. Expression

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

I Internal Examination Sept Class: - BCA I Subject: - Principles of Programming Lang. (BCA 104) MM: 40 Set: A Time: 1 ½ Hrs.

ECET 264 C Programming Language with Applications

Introduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands

CSE 30 Fall 2013 Final Exam

Operators & Expressions

ECET 264 C Programming Language with Applications

JAVA OPERATORS GENERAL

CS103L FALL 2017 UNIT 1: TYPES, VARIABLES,EXPRESSIONS,C++ BASICS

Operators and Expressions:

DEPARTMENT OF MATHS, MJ COLLEGE

Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators

Reserved Words and Identifiers

Engineering Computing I

Computer Programming CS F111

Lecture 3. More About C

Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah. Lecturer Department of Computer Science & IT University of Balochistan

Structures, Operators

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information

Introduction to C. Systems Programming Concepts

COMP26120: Pointers in C (2018/19) Lucas Cordeiro

C/C++ Programming Lecture 7 Name:

3. Types of Algorithmic and Program Instructions

Work relative to other classes

Computers Programming Course 5. Iulian Năstac

BCA-105 C Language What is C? History of C

Midterm CSE 131 Winter 2012

COMP1917 Computing 1 Written Exam Sample Questions

CC112 Structured Programming

Module 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1

OBJECT ORIENTED PROGRAMMING

Information Science 1

Computer System and programming in C

Slide Set 2. for ENCM 335 in Fall Steve Norman, PhD, PEng

CMSC 104 -Lecture 6 John Y. Park, adapted by C Grasso

Operators And Expressions

POINTER & REFERENCE VARIABLES

These are reserved words of the C language. For example int, float, if, else, for, while etc.

Fundamental of C programming. - Ompal Singh

ME 461 C review Session Fall 2009 S. Keres

Fundamentals of Programming Session 8

CSE 1001 Fundamentals of Software Development 1. Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018

Embedded Systems - FS 2018

Dept. of CSE, IIT KGP

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

COMP Primitive and Class Types. Yi Hong May 14, 2015

Le L c e t c ur u e e 2 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Variables Operators

CSCI 2212: Intermediate Programming / C Chapter 15

Programming for Engineers: Operators, Expressions, and Statem

Basic Assignment and Arithmetic Operators

Basics of Programming

Structured Programming. Dr. Mohamed Khedr Lecture 4

Fundamentals of C. Structure of a C Program

Expressions. Arithmetic expressions. Logical expressions. Assignment expression. n Variables and constants linked with operators

Introduction to C Language

Data Type Fall 2014 Jinkyu Jeong

Outline. Performing Computations. Outline (cont) Expressions in C. Some Expression Formats. Types for Operands

JAC444 - Lecture 1. Introduction to Java Programming Language Segment 4. Jordan Anastasiade Java Programming Language Course

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

CSE 30 Fall 2012 Final Exam

BITG 1233: Introduction to C++

Transcription:

UNIVERSITY OF LIMERICK OLLSCOIL LUIMNIGH COLLEGE OF INFORMATICS & ELECTRONICS DEPARTMENT OF ELECTRONIC & COMPUTER ENGINEERING MODULE CODE: MODULE TITLE: ET4131 Introduction to Computer Programming SEMESTER: Autumn 2005 DURATION OF EXAM: LECTURER: 2.5 Hours Tom Newe INSTRUCTIONS TO CANDIDATES: Part A : - 30% (Multiple Choice) all 10 questions. Only one correct answer per question. All questions carry equal marks. Correct answer = 3% Wrong answer = 0% No answer = 0% Part B:- 40% (Written) 2 Questions only. All Questions carry equal marks. Operator precedence sheet attached. (% Lab Worth = 10%) and (% Mid Term = 20%) Questions on Exam Paper in Space provided. CALCULATORS NOT ALLOWED Student Name: Student ID: Course:

--------------------------------------PART A-------------------------------------- All Questions in Part A worth 3% each. (Total 30%) -------------------------------------------------------------------------------------- Q.1 What is the binary equivalent of 136 16? (a) 0010 1100 0110 (b) 0100 0011 0110 (c) 0001 0011 0110 (d) 0001 0111 1100 (e) 0100 0100 1110 Q.2 What is the Hexadecimal equivalent of 14 10? (a) C 16 (b) D 16 (c) E 16 (d) F 16 (e) None of the above. Q.3 What is the decimal equivalent of 10 16 (Hexadecimal)? (a) 15 10 (b) 16 10 (c) 17 10 (d) 18 10 (e) None of the above. Q.4 What does the term PSEUDO CODE refer to? (a) Mix of symbols and text to represent an algorithm. (b) Text based representation of an algorithm. (c) Graphical representation of an algorithm. (d) None of the above. (e) More than one of the above. Q.5 What does the term SYNTAX refer to in a programming language? (a) Correct use of punctuation/formatting. (b) How something is written. (c) How something is structured. (d) The meaning of a command. (e) More than one of the above. Page 1 of 13

Q.6 What is the result of the following expression? 10 4 + 3 * 2 (a) 0 (b) 12 (c) 18 (d) 6 (e) None of the above. Q.7 What is the result of the following expression? (10 + 4 2) * 3 % 5 (a) 4 (b) 3 (c) 2 (d) 1 (e) None of the above. The following program is used for questions 8, 9 and 10. /*--------------------------------------------------- * File Name :bits.c * Function :Bitwise operations on numbers. *--------------------------------------------------*/ #include <stdio.h> /* Standard I/O library */ void main(void) /* Main program, no return value*/ { /* Hex numbers */ int i = 0x1C, j = 0x20; } printf( i = (%d,0x%x), j = (%d,0x%x)\n\n, i, i, j, j); printf( i j = 0x%X\n, i j); printf( i & j = 0x%X\n, i & j); printf( i ^ j = %6d\n, i ^ j); printf( i << 3 = 0x%X\n, i << 3); printf( j >> 2 = 0x%X\n\n, j >> 2); printf( i >> 2 << 2 = 0x%X\n, i >> 2 << 2); printf( ~i & ~j i = 0x%X\n, ~i & ~j i); Continued over Page 2 of 13

Q8. What is displayed on the screen by the first printf statement? (a) i = (27,0x1C), j = (32,0x21) (b) i = (28,0x1C), j = (32,0x20) (c) i = (29,0x1C), j = (31,0x20) (d) i = (30,0x1C), j = (31,0x21) (e) None of the above. Q.9 What is displayed on the screen by the seventh printf statement? (a) i >> 2 << 2 = 0x1C (b) i >> 2 << 2 = 0x0C (c) i >> 2 << 2 = 0x1D (d) i >> 2 << 2 = 0x0B (e) None of the above. Q.10 What is displayed on the screen by the fourth printf statement? Note that represents a space. (a) i ^ j = 0x3C (b) i ^ j = 60 (c) i ^ j = 60 (d) i ^ j = 0x3C (e) None of the above. Page 3 of 13

--------------------------------------PART B-------------------------------------- All Questions in Part B worth 20% each 2 Questions only (Total 40%) --------------------------------------------------------------------------------------- Q.1 A Patio supplier supplies patio slabs on a cost per square metre (area) basis. Your task is to write a C program that allows the supplier to calculate the cost of a patio. This is to include the facility of calculating the cost of rectangular, circular and semicircle patterns where: Area of a rectangle = length * width Area of a Circle = PI * radius * radius Area of a semi-circle = (PI * radius * radius) / 2 and PI = 3.1415926 Your program is to loop continuously and keep a running TOTAL area of all areas calculated in that session until the user decides to end the session. {20%} Ans: Page 4 of 13

Page 5 of 13

Q.2 Write a C program to display a square on screen that is composed of a symbol. The length of the side of the square and the symbol it s composed of are entered as input from the keyboard. For example, if the input values are 4 and *, the output would be as follows: **** **** **** **** Your solution is to use at lease one function called square, which has the following function definition: void square(int length, char symbol); {20%} Ans: Page 6 of 13

Page 7 of 13

Q.3 Write a C program to read in measurements from a user. The entered measurements are in inches and your program is to convert the entered value into millimetres and re-display it on the screen. The conversion formula is as follows: 1 inch = 25.4 mm ex. 10 Inches = 254mm; Ans: The program is to continue looping until the user enters a value of -1 for inches. This will end the program. Your solution is to use at lease one function called convert, which has the following function definition: float convert(int inches); The return value from this function is the converted value in millimetres. Ex: milli = convert(10); // From this milli is equal to 254.00 {20%} Page 8 of 13

Page 9 of 13

Spare Sheet for Q: Page 10 of 13

Spare Sheet for Q: Page 11 of 13

Spare Sheet for Q: Page 12 of 13

Operator Priority Table : Operator Description Example Associativity ( ) Function call sqrt(x) L to R [ ] Array element ref val[2] -> Ptr to structure member mem_ptr -> name. Structure member ref member.no - Unary minus -10 R to L ++ Increment k++ ++k -- Decrement --count count--! Negation!number ~ One s complement ~0x2F * Pointer Indirection *ptr & Address of &x sizeof Size in bytes sizeof(float) (type) Cast/Type conversion (float) sum / n * Multiplication x * y L to R / Division x / y % Modulus x % y + Addition a + b L to R - Subtraction a - b << Left shift test << 4 L to R >> Right shift test > 3 < Less than x < 10 L to R <= Less than or equal to x <= 3 > Greater than f > 5 >= Greater than or equal to d >= 6 == Equal to count == 4 L to R!= Not equal to count!= 3 & Bitwise AND num & 0x10 L to R ^ Bitwise Exclusive OR num ^ 0x32 L to R Bitwise OR num 3 L to R && Logical AND x > 4 && t < 8 L to R Logical OR x == 3 f < 9 L to R?: Conditional Expression (t > j)? t : j R to L = *= /= %= Assignment j = 4; R to L += -= &= ^= j += 2; num &= 3; = <<= >>= num >>= 2, Sequence (comma) k = 0, g = 4; L to R Page 13 of 13