0% found this document useful (0 votes)
21 views6 pages

Structured Programming Assignment Guide

The document outlines an assignment for a structured programming course, including various questions related to C programming concepts such as file handling, structures, and programming errors. It instructs students to attempt all questions and submit their work by a specified date, with references included. Additionally, it covers topics like algorithm definitions, programming errors, and examples of C programs for various tasks.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views6 pages

Structured Programming Assignment Guide

The document outlines an assignment for a structured programming course, including various questions related to C programming concepts such as file handling, structures, and programming errors. It instructs students to attempt all questions and submit their work by a specified date, with references included. Additionally, it covers topics like algorithm definitions, programming errors, and examples of C programs for various tasks.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

TAKE AWA'i ASSIGNMENT

Instructlons:

Attempt all the questions


th
Submit 'your work on or before by 11 August, 2018

Include the references at the end of the attempted questions

GENERAL

1. Explain the difference between call by value and call by reference

FILE HANDLING IN C

2. What Is significance of EOF


3. What is a file
4. List the common functions used for reading info frorn and writing info to text files

STRUCTURES AND UNION

5. What is the difference among structure, array and union


6. Write a program in C using structure to calculate total marks and average marks obtained by 8
students in 4 different subjects

,dt.
"1j.. lflr 1 .(.J>'l ~l, ~ l >
1Nl v i:l{ 1 ,,·lt\ 11\! I.)
),-,½ MG.',~,

BIT STRUCTURED PROGRAMMING CAT 1


,\ fOC,~ !, I

1l'l'.~,t ('I £_ Aht-,1q 1pt ALL the Q,u.e:stions


,,,l{ ( f\lll'l" i..'( ' \ fl ) }
20-6--2018
'f· ' I' \\ J-\O i>A l ",b)\
..rro tyf- \... IJ~-1 ~1. Define [2 marks)
~• rJ,t a. Algorithm- rNif~ N\o.)-\C r, I
b. identifier - ~(lri_ obl~ ) f\ ifl"I"'-
2. Describe 4 basic data types in C, include the type of dat2 , the number of bytes and conversion
characterofthe typf [8 rna ' k$)
3. Write a simple C program to receive two float values from the user afld display the sum on the
screen [4 ma rks)
4. Explain _2 logical operators and 2 increment/ decrement operators (4 marks]
LOj, (~\ Cf'<"''>v1.1 - ~ - "lo 01t ,
1

d 1/\ p( ,d ' , ..\/J(t)il'rU\ ~' '\ft 1(Ut'


_j
'~

l\ ltl ll 11 t l<e11,ra
1
~
U 11iversity
~ )

UNIVERSITY EXAMINATION 2017/2018

SCHOOL OF COMPUTING AND INFORMATICS


DEPARTMENT OF INFORMATION TECHNOLOGY

BBIT/BSC IT
REGULAR

UNIT CODE: BIT1208 UNIT TITLE: STRUCTURED


PROGRAMMING

DATE:AUGUST, 2018 MAIN EXAM TIME: 2 HOURS

INSTRUCTIONS: ANSWER ALL QUESTIONS IN QUESTION ONE AND ANY OTHER


TWO QUESTIONS

QUESTION ONE (30 Marks)

a) State FOUR advantages of structured programming. (4 Marks)

b) Define the following terms:, 'iD/\..1 c• ,,,\ r,> (•'\ , n t"'' L'f,n (10 Marks)
i. Algorithm , {~-! G\ 1•'J r, lll'

ii. Structured programming. LI,_ '" ,, _, , _, .... J


11
iii. Reserved words · "· 11 ,· • • • J '
. , I' '1
iv. Constant - v""""l:,'~ 1\••·-1 ii ' ,\
\•,(I L d I" I \.I' ",
V. Pointers - re, h 0,
~c /- c- J
' \'- , ~ \'·!
\_, (' \
c) Differentiate between :!±- and ..:..:. operator as po_stfix and prefix. (2 Marks)
1 , ;d.J C)i\( )1) l .,,.i.,· ~YI .ft !-\.,, ~-(fw{ " 1 'q
- - _0.)!.,h.,cJ ,r, r'll J ~-~,-J!,ll
1

dJ With an aid of a c program explain how [Link] operators work. (3 Marks)

e) Name and explain THREE programming errors . (6 Marks)


\. ~-,,. I I I r.l 1. ' a.u r ...., (

f1 List THREE examples of high level languages. (3 Marks)


J c,.vr1
C,

Paper one Page 1


g) State two reasons for the shift from machine language
(2 Marks)
to assembly language.

QUESTION TWO (20 Marks)

a) Define an array. (2 Marks)

b) Write a C program to check whether a number entered by user is even or


odd . (4 Marks)

c) Write a c program that asks the user to enter an integer and this program
will generate the multiplication table up to 5. (5 Marks)
c.0 \"-h1 k C\ r',,,J'''"' h:J ,f o r'j root! 01 Cl ~UC!dn.h c.. f q,uei ~o•'l (cl n') a,~-0
QUESTION THREE (20 Marks)
~ o,I ~ f?

a) Draw and explain FOUR symbols used in a flowchart. O C:) C7 (8 Marks)


(>c "" 'hl,.::t\
L:,r , r ''j ,J~,,
b) State and explain the stages of program development lifecycle (pdlc) . 1 • ,,1

I ,. ~ '1 -:I OJ.J (I


(, brc.. ,,-1lv1rN"j ~~t h;J • ,. 1r-
1.._. I'~ ar'\ a1••1j -, ~!1' ~ 1!'.--1) (6 Marks) c. c:-d •nfl •· ·"••i -
£1 U,fl I l" 'L
r: JI(! , ~ I'" (
, 1, L
--1 n h J J d ,c.,_11••' )
u'v \ (II ,;j._,i1
I ti •-U< J,r ':'fT'l-'ni
c) Distinguish between 1st generation and 4th generation programming
languages. (4 Marks)

QUESTION FOUR (20Marks)

a) State two advantages of modular approach in programming .


(2 Marks)

b) Distinguish between each of the following pairs of stn1ctured programming


terms:
i. Pass by value and pass by reference (4 Marks)
ii. Source code and object code (4 Marks)

c) Outline three types of program documentation . (3 Marks)

d) Outline two uses of comments in a structured program . (2 Marks)

e) Write a program that will prompt the user to enter a number. The program
determines the square root of the number through a built-in function and
displays the result on the screen. (5 Marks)
/(
' 1/'v
J

Paper one Page 2


QUESTION FIVE (20 Marks)

itJI '\-
a) Explain the term nested -if control structure. I I 111 I I
1 11

! I( 1
l l j 1f (lf·!

t~< , I
(2 Marks)
, 1' \

b) Using a diagram describe the while loop. (3 Marks)

-~c) Write a C program that sums all integers from 10 to 70. Use
the for statement. 1 (5 Marks)
/; /
t I

d) The table below shows the charges applicable to different an¾ounts of water
consumed by clients in a particular town. /,., 1

Volume of water
Consumption in Ksh
consumed in M3
I. 0-16 200
'\ C
II . 10-20 350
111 . 20-30 500
IV. Over 30 1000

In addition to the consumption, the amount of the water bill will consist of a
standing charge of Ksh 200 and a sewerage fee equivalent to 20% of the
consumption.
Write a C program that prompts a user to enter the volume of water
consumed. The program then computes and outputs the amount of the
water bill. Use if.. . else control structure. (10 Marks)

I"' ~ ,,,.., .. , ' I I i


,\ I o, 1 I ,J ,l, 'J ;
,µ,~ 1~;ioo

l --1
I··'
1'

I , ~

!t

'l J'

Paper one Page 3

j
Mount Kenya '~ ~JUniversity
UNIVERSITY EXAMINATION 2016/2017

SCHOOL OF SCHOOL OF COMPUTING AND INFORMATICS


DEPARTMENT OF INFORMATION TECHNOLOGY

BIT/BBIT /BIT
VIRTUAL CAMPUS

UNIT CODE: BIT1208 UNIT TITLE: STRUCTURED PROGRAMMING

DATE: DECEMBER 2016 MAIN EXAM TIME: 2 HOURS

INSTRUCTIONS: ANSWER ALL QUESTIONS IN SECTION A AND ANY OTHER TWO FROM
SECTION B

SECT!ON A (Ccmpu!sory)

QUESTION ONE (30 marks)

a) List four Rules and Conventions for naming variables and constants in C.
[4 marks]
b) Explain using examples how to declare variable and initialize variable .
[4 marks]
c) Difference between union and structure. [4 marks]

d) Distinguish between gets() function and puts() with the help of an example.
[6 marks]
e) Use a flow chart to explain the three main program control structures
[6 Marks]
f) Differentiate between the following programming concepts [6 marks]
i. Loosely typed and strongly typed languages
ii. Pseudo code and Algorithms
· Linking and compiling

Paper One Page 1


SECTION B (Answer any two questions)

QUESTION TWO (20 marks)


j) Write a C program to multiply two matrices using multi-dimensional arrays .
[10 marks]
b) Implement a structure called Student in C with the following members.
\f,t-ru ~k ~ "!:- i [10 marks]
i. Student name C\1-t:ll' wl~ , t - t1<1tYU-
11' \- t1jlJtr"lhU" -tllJrl'I
ii . Registration Number
iii. Marks 11* \:; r(l t1 Ti-1-J j ;
rflO-: L
~ , 11.\C.'-
._r ./-u cfr 11 {- ..[
P' , h - PJ
QUESTION THREE (20 marks)

a) Write a program in C to find the area and perimeter of a circle. [10 marks]

b) Write a program in C to make a simple calculator to Add, Subtract, Multiply or


Divide Using switch .. .case. [10 marks]

~ UESTION FOUR (20 marks)

a) Using arrays , write a program to calculate average of 5 numbers


[10 marks]
b) Explain four characteristics of a good algorithm . [4 marks]

c) Develop a flowchart to accept the length and width of a rectangle and


calculate its area. [6 marks]

QUESTION FIVE (20 marks)

a) Using binary search write a program in C programming to search a given


number from a given list [10marks]

b) Write a Program to demonstrate Recursion in functions [6 marks]

c) State and explain any four categories of operators [4 marks]

Paper One Page 2

Common questions

Powered by AI

A structure in C allows defining a complex data type that groups variables of different types into a single unit, with each member having its memory space. In contrast, a union provides a way of storing different data types in the same memory location, allowing access to different members at different times but sharing the same memory address. Structures are typically used when all members are required to hold their values together, while unions are beneficial when only one member is needed at any time, optimizing memory usage .

High-level languages like C, Python, and Java abstract the complexity of machine and assembly languages, offering syntax that is closer to human languages. They handle memory management and machine-specific instructions internally, freeing programmers to focus on logic and problem solving. This abstraction promotes faster coding, better accessibility to programming across different platforms, and significantly reduces the time needed to develop, test, and maintain programs, compared to the meticulous and lower-level syntax required by machine and assembly languages .

The advantages of structured programming include improved readability, easier maintenance, enhanced quality, and greater productivity. Structured programming emphasizes breaking down a program into smaller modules or functions, making it easier for programmers to understand the flow of the program and identify errors . By promoting code modularity, it helps maintain complex codebases more efficiently. This approach also leads to improved quality, as each module can be individually tested and verified before integration. Furthermore, structured programming encourages productivity by allowing multiple programmers to work on different modules simultaneously, promoting better collaboration and faster development .

Typical programming errors include syntax errors, runtime errors, and logical errors. Syntax errors, resulting from incorrect use of language rules, are typically detected at compile time. Runtime errors occur during execution when the program encounters invalid operations. Logical errors, more challenging to detect, cause unexpected behavior due to incorrect logic. These errors impact software development by potentially introducing delays, increasing debugging time, and affecting the reliability and functionality of the software product if not addressed systematically .

In C programming, 'call by value' refers to passing a copy of the actual parameter's value to the function, meaning changes made within the function do not affect the original variable outside the function. Conversely, 'call by reference' involves passing the address of the actual parameter, allowing the function to modify the original variable directly. This distinction is crucial for memory management and performance optimization in large programs .

Logical operators, such as '&&' (AND) and '||' (OR), are used in C programming to evaluate multiple conditions, enabling complex conditional expressions in decision-making structures. Increment ('++') and decrement ('--') operators are used to increase or decrease a variable's value by one, often employed in loops or iterative operations to control the flow of execution. The combination of these operators allows for more concise and efficient code manipulation .

Conditional operators in C, such as '?:' (ternary operator), evaluate expressions and execute code based on condition outcomes, offering a shorthand form of 'if-else' statements. This operator is significant in control structures as it allows concise, readable code, especially useful in scenarios requiring simple conditional checks and assignments within expressions. The efficiency and simplicity of conditional operators enhance the readability and performance of programs .

The program development lifecycle (PDLC) provides a structured approach to software development, ensuring systematic progress from problem definition to application deployment. Its main stages include: requirement gathering, design, implementation, testing, deployment, and maintenance. Each stage serves a specific purpose, with early stages focusing on planning and analysis to ensure accurate software solutions, and later stages emphasizing testing and deployment to ensure robust implementation. This lifecycle optimizes resource use, reduces risks, and assures quality in software production .

Modular programming is important because it divides programs into smaller, manageable, and independent modules, each with specific functionalities. This approach facilitates easier testing and maintenance, improves code reusability, and allows multiple developers to work on different modules simultaneously, enhancing collaboration and productivity . As a result, it significantly improves the quality and scalability of software development practices by promoting efficient resource utilization and minimizing development time.

Loosely typed languages allow for more flexibility by not enforcing strict type definitions. They interpret data types at runtime, offering ease of use but potentially leading to runtime errors. Examples include Python and JavaScript. Strongly typed languages, such as C and Java, enforce strict type rules at compile time, requiring explicit variable type declarations, which can prevent errors but necessitate more extensive code. This distinction affects error handling, performance, and the robustness of coded applications .

You might also like