DEPARTMENT OF ELECTRICAL AND ELECTRONIC ENGINEERING PROGRAMMING TECHNIQUES I EE271

Similar documents
UNIVERSITY OF SWAZILAND

M1-R4: Programing and Problem Solving using C (JULY 2018)

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

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

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

IECD Institute for Entrepreneurship and Career Development Bharathidasan University, Tiruchirappalli 23.

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

INTI COLLEGE MALAYSIA

Fundamental of Programming (C)

.. Cal Poly CPE 101: Fundamentals of Computer Science I Alexander Dekhtyar..

Decision Control Structure. Rab Nawaz Jadoon DCS. Assistant Professor. Department of Computer Science. COMSATS IIT, Abbottabad Pakistan

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

BLM2031 Structured Programming. Zeyneb KURT

Multiple Choice Questions ( 1 mark)

DECLARATIONS. Character Set, Keywords, Identifiers, Constants, Variables. Designed by Parul Khurana, LIECA.

Make sure the version number is marked on your scantron sheet. This is Version 1

A Fast Review of C Essentials Part I

C: How to Program. Week /Mar/05

Fundamentals of Programming

Name :. Roll No. :... Invigilator s Signature :.. CS/B.TECH (NEW)/SEM-2/CS-201/ BASIC COMPUTATION & PRINCIPLES OF COMPUTER PROGRAMMING

Name :. Roll No. :... Invigilator s Signature : INTRODUCTION TO PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70

Data Types and Variables in C language

C Language, Token, Keywords, Constant, variable

Formatting functions in C Language

M3-R4: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE

2/29/2016. Definition: Computer Program. A simple model of the computer. Example: Computer Program. Data types, variables, constants

Chapter 2 - Introduction to C Programming

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

VARIABLES AND CONSTANTS

Chapter 1 & 2 Introduction to C Language


C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved.

C Fundamentals & Formatted Input/Output. adopted from KNK C Programming : A Modern Approach

CCE RR REVISED & UN-REVISED KARNATAKA SECONDARY EDUCATION EXAMINATION BOARD, MALLESWARAM, BANGALORE G È.G È.G È..

CS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011. MIDTERM EXAMINATION Spring 2010

Programming and Data Structure Solved. MCQs- Part 2

PYTHON- AN INNOVATION

Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and

Introduction to C Programming. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan

6.096 Introduction to C++ January (IAP) 2009

Data types, variables, constants

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

Rule 1-3: Use white space to break a function into paragraphs. Rule 1-5: Avoid very long statements. Use multiple shorter statements instead.

Unit 4 Preprocessor Directives

Functions. Lab 4. Introduction: A function : is a collection of statements that are grouped together to perform an operation.

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

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

ANSI C Programming Simple Programs

Name Roll No. Section

Programming in C++ 4. The lexical basis of C++

Faculty of Engineering Computer Engineering Department Islamic University of Gaza C++ Programming Language Lab # 6 Functions

Lecture 03 Bits, Bytes and Data Types

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

COMPUTER SCIENCE HIGHER SECONDARY FIRST YEAR. VOLUME II - CHAPTER 10 PROBLEM SOLVING TECHNIQUES AND C PROGRAMMING 1,2,3 & 5 MARKS

Differentiate Between Keywords and Identifiers

Decision Making -Branching. Class Incharge: S. Sasirekha

INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR Stamp / Signature of the Invigilator

University of California San Diego Department of Electrical and Computer Engineering. ECE 15 Final Exam

The C++ Language. Arizona State University 1

DEPARTMENT OF MATHS, MJ COLLEGE

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

BSM540 Basics of C Language

sends the formatted data to the standard output stream (stdout) int printf ( format_string, argument_1, argument_2,... ) ;

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

Basic Elements of C. Staff Incharge: S.Sasirekha

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

UNIT IV 2 MARKS. ( Word to PDF Converter - Unregistered ) FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING

Creating, Compiling and Executing

UIC. C Programming Primer. Bharathidasan University

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University

Introduction to C Final Review Chapters 1-6 & 13

CSE 2421: Systems I Low-Level Programming and Computer Organization. Functions. Presentation C. Predefined Functions

Programming and Data Structures

PES INSTITUTE OF TECHNOLOGY (BSC) I MCA, First IA Test, November 2015 Programming Using C (13MCA11) Solution Set Faculty: Jeny Jijo

Subject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100

University of Maryland College Park Dept of Computer Science CMSC106 Fall 2013 Midterm I Key

Approximately a Final Exam CPSC 206

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

SOFTWARE Ph.D. Qualifying Exam Fall 2017

Reviewing all Topics this term

COP 3223 Introduction to Programming with C - Study Union - Spring 2018

1. The keyword main in C language is used for

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

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

EECE.2160: ECE Application Programming Spring 2016 Exam 1 Solution

Chapter 2. Section 2.5 while Loop. CS 50 Hathairat Rattanasook

بسم اهلل الرمحن الرحيم

The Hyderabad Public School, Begumpet, Hyderabad, A.P

Fundamentals of Programming Session 15

'C' Programming Language

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

CSCI 2132 Software Development. Lecture 20: Program Organization

LESSON 4. The DATA TYPE char

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

Informatica e Sistemi in Tempo Reale

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

Fundamentals of Programming

INTRODUCTION 1 AND REVIEW

Computers Programming Course 7. Iulian Năstac

Case Control Structure. Rab Nawaz Jadoon DCS. Assistant Professor. Department of Computer Science. COMSATS IIT, Abbottabad Pakistan

Transcription:

UNIVERSITY OF SWAZILAND FACULTY OF SCIENCE AND ENGINEERING DEPARTMENT OF ELECTRICAL AND ELECTRONIC ENGINEERING MAIN EXAMINATION: 2015 TITLE OF PAPER: COURSE NUMBER: TIME ALLOWED: PROGRAMMING TECHNIQUES I EE271 3 HOURS INSTRUCTIONS: ANSWER ALL FIVE (5) QUESTIONS. MARKS FOR DIFFERENT SECTIONS ARE SHOWN ENCLOSED IN SQUARE BRACKETS. THIS PAPER HAS SEVEN (7) PAGES INCLUDING THIS PAGE. DO NOT OPEN THE PAPER UNTIL PERMISSION HAS BEEN GIVEN BY THE INVIGILATOR.

QUESTION 1 (10 Marks) Choose the correct letter for the answer in each ofthe following options. Each correct answer or choice carries [1] mark. 1.1 Memory unit is one part of A. Input device B. Control unit C. Output device D. Central Processing Unit 1.2 The loop in which the statements within the loop are executed at least once is called: A. do-while B.while C. for D. goto 1.3 The statement which is used to terminate the control from the loop is: A. exit B. break C. continue D. goto 1.4 Which amongst the following is not a keyword? A. float B. external C. int D. double 1.5 Which of the following number system/code uses only Os and 1 s A. decimal B. octal C. hexadecimal D. none of the above 1.6 Which of the following is FALSE in C. A. Keywords can be used as variable names B. Variable names can contain a digit 2

C. Capital letters can be used in variable names D. Variable names do not contain a blank space 1.7 Each C preprocessor directive begins with A# B. include C. main () D. { 1.8 The C language includes the header file standard input & output in A stdlib.h library B. stdio.h library C. conio.h library D. #include library 1.9 A variable which is visible only in the function in which it is defined, is called A static variable B. auto variable C. external variable D. local variable 1.10 The function fprintf is used in a program A When too many printf calls have been already used in the program B. In place of printf, since printf uses more memory C. When the output is to be printed on to a file D. When the type of variables to be printed are not known before QUESTION 2 (15 Marks) a) What is the output ofthe following program fragment int x = 5; int y = x++; printf("%d%d", x, y); [2] b) What is the output of the following program segment? main ( ) 3

float a = 0.5, b = 0.7; if (b < 0.8) if (a < 0.5) printf ("ABeD"); else printf ("PQR"); else printf ("JKLF); [2] c) What is the output of the following program segment? main () { int i = 1; do { printf("%d.~", i); while(i--); [2] d) What will be the output of following program? main () { int 5; printf("\n%d%d%d", x! 5, 0, x<30); [3] e) Describe the output of the following C program fragment void main () { int k 0, x = 0; while (k < 25) { if (k % 5 == 0) { x += k; printf("%d ", x); ++k; printf("\nx=%d ", x +k); ~ 4

QUESTION 3 (25 Marks) a) Write a switch statement that will examine the value of an integer variable and print the following messages: It is hot weather; if the integer value is 1 It is a stormy weather; if the integer value is 2 It is sticky weather; if the integer value is 3 It is a pleasant weather; otherwise b) Design an algorithm that accepts a positive integer and reverses the order of its digits [5] [6] c) While purchasing certain items, a discount of 10% is offered if the quantity purchased is more than 1000. If the quantity and price per item are input through keyboard, write a program to calculate the total expenses. [7] d) Write a function, which takes an array of real numbers and its size as arguments and returns the maximum. Using the above function write a program to read a set of real numbers from the keyboard and find the maximum number in the array.[7] QUESTION 4 (25 Marks) A small airline has just purchased a computer for its new automated reservations system. The president has asked you to program the new system. You are to write a program to assign seats on each flight of the airline's only plane (capacity: 10 seats). Your program should display the following menu of alternatives: Please type 1for ''first class" Please type 2for "economy" If the person types 1, then your program should assign a seat in the first class section (seats 1-5). If the person types 2, then your program should assign a seat in the economy section (seats 6-10). Your program should then print a boarding pass indicating the person's seat number and whether it is in the first class or economy section ofthe plane. 5

Use a single-subscripted array to represent the seating chart of the plane. Initialize all the elements of the array to 0 to indicate that all seats are empty. As each seat is assigned, set the corresponding elements ofthe array to 1 to indicate that the seat is no longer available. Your program should, of course, never assign a seat that has already been assigned. When the first class section is full, your program should ask the person if it is acceptable to be placed in the economy section (and vice versa). If yes, then make the appropriate seat assignment. If no, then print the message "Next flight leaves in 3 hours." Your program will be graded according to the following criteria: i) Correctness - does the program produce the desired result. [18] ii) Clarity - proper indentation ofprogram makes it easy to read. [2] iii) Sensible naming of variables -makes it easy to tlnderstand code whendebugging. [3] iv) Proper use ofcomments - comments also make the program easy to undestand. [2] QUESTION 5 (25 Marks) a) Convert the following code to use a "do-while" loop instead of for loop. [5] #include <stdio.h> int main (void) { int ij for (i=25j i >=0; i--) printf("%c", 'z'-i); printf("\n") ; return OJ b) Write a complete C program that uses a recursive function named Power. The program should prompt the user to enter the base and the exponent values as integers, and then display the output computed by the function Power. The recursive function Power( base, exponent) when invoked returns baseexponent For example, Power( 5, 4) 5 * 5 *5 *5. Assume that exponent is an integer greater than or equal to 1. Hint: The recursion step would use the relationship 6

base exponent = base * baseexponent-l and the terminating condition occurs when exponent is equal to 1 because basel = base Note: You do not need to include comments in your program [20] 7