Sunday, November 15, 2015
Pascal Arithmetic Program Using IF THEN statement
YOU MIGHT ALSO LIKE: Pascal Program To Create And Save Records In A Textfile
Program Basic_Arithmetic;
Uses crt;
Label 20;
Var A, B, Sum, Subtract, Divide, Multiply, Average: Real;
Choice : Integer;
YN : Char;
Begin
20 : Clrscr;
Writeln (' For addition, press 1');
Writeln (' For subtraction, press 2');
Writeln (' For Divison, press 3');
Writeln (' For multiplication, press 4');
Writeln ('To calculate Average, press 5');
Writeln ('To exit, Press 6');
Writeln ('Enter a number of your choice');
Choice := Readkey;
If choice = '1' then
Begin
Writeln (' Enter your first number');
Readln (A);
Writeln ('Enter your second number');
Readln (B);
Sum := A + B;
Writeln (' The answer is', Sum);
Goto 20;
End;
If choice = '2' then
Writeln ('Enter your first number');
Readln (A);
Writeln ('Enter your second number');
Readln (B);
Subtract := A - B ;
Writeln ('The answer is', Subtract);
Readln;
Goto 20;
End;
If choice = '3' then
Writeln ('Enter your first number');
Readln (A);
Writeln ('Enter your second number');
Readln (B);
Divide := A / B;
Writeln ('The answer is', divide);
Readln;
Goto 20;
End;
If choice = '4' then
Writeln ('Enter your first number');
Readln (A);
Writeln ('Enter your second number');
Readln (B);
Multiply := A * B
Writeln ('The answer is', multiply);
Readln;
Goto 20;
End;
If choice = '5' then
Writeln ('Enter your first number');
Readln (A);
Writeln ('Enter your second number');
Readln (B);
Sum := A + B;
Average := Sum / 2 ;
Writeln ('The answer is:', Average);
Readln;
Goto 20;
End;
If choice = '6' then
Writeln (' You are about exiting this program, to continue press Y/N');
YN := Readkey;
If YN = 'Y' then
Writeln (' Goodbye');
Halt;
If YN = 'N' then
goto 20;
end;
End.
If you have more numbers you can use a looping statement which will save time instead of the If then statement.
Past Question Computer Laboratory 2010/2011
DEPARTMENT OF MATHS/STATISTICS AND COMPUTER SCIENCE
FIRST SEMESTER EXAMINATION 2010/2011
COURSE: CSC 1181 – COMPUTER SCIENCE LABORATORY 1A TIME: 1 Hour
INSTRUCTIONS: ANSWER ALL QUESTIONS.
Write your NAME, REG NUMBER, JAMB NUMBER AND COURSE ID Clearly on your Answer Booklet. Do not write anything on your question paper except your name and registration number.
SECTION A
1. (a) Write short notes on the following terms in BASIC:
I) Constants II) Variables III)Keywords. Give 2 examples of each.
(b) State 3 rules for the formation of BASIC statements and expressions.
(c) How would you express the given algebraic term in BASIC? √(3a2-4c) * 35
2. (a) Differentiate between Numeric data and String data and give 2 examples of each.
(b) Write a program to compute and print out the sum and average of the ages of any given number of students, say n.(Hint: Let your n be = 7)
(c) State 2 features of READ – DATA statement. Why would you use INPUT statements in your BASIC program instead of Read – DATA statements?
3. (a) I) State 2 features of a Subroutine.
II) How are Subroutines similar to functions ?
(b) Write a GW-BASIC program to define a function X to compute X = ( Y4 + Y3 – 2Y2 + 2/Y) . Use the FOR-TO-NEXT construct. Print out values of the function X for values of Y ranging from 10 to 20 with step size of 2.
(c) What is an array? What is the use of the DIM statement in an array? Use a clear example to show the DIM statement is written.
SECTION B
1. Load the GW-BASIC Interpreter.
2. Key in and debug the program you wrote in either question 2(b) or 3(b) in section A.
3. Save your program, Using your registration number as the filename.
Some examples of filenames are: 1050160 for Matric No. 10/50160; 4567AA for a Jamb No 21234567AA; P0900235 for Pre-degree No. PDS-1/09/00235, and K800927 for pre-degree No. 2k8/000927.
Past Question Introduction to Computer Science 2007
DEPARTMENT OF MATHS/STATISTICS & COMPUTER SCIENCE
COURSE: CSC 1101 – INTRODUCTION TO COMPUTER SCIENCE
DATE: Tuesday, 24th July, 2007
INSTRUCTIONS: ANSWER ANY FOUR (4) QUESTIONS
1. (a) The decision symbol is the only symbol of a flowchart with two exit points. What are these exit points? Illustrate with an example.
(b) The history of computer cannot be complete without Charles Babbage. Justify this statement.
(c) The stored program concept of John Von Neumann is very famous. What is it all about?
2. (a) I. Using appropriate examples, differentiate between one’s (1’s) complement and two’s (2’s) complement? Also, differentiate between LSB abd MSB in binary arithmetic, using an example to support your answer.
(b) I. Clearly differentiate between a microcomputer and an embedded computer.
II. Give an area of importance each of the hexadecimal and binary number systems respectively in computer technology.
(c) What is a microprocessor? Why is it very important when discussing generations of computer development?
3. (a) Describe the components of the central processing unit (control unit and ALU). Give four examples of Input devices and two examples of output devices as part of computer hardware.
(b) What is an operating system? Give two examples of a single-user operating system, and one example of a multi-user operating system.
4. (a) What makes computers different from other devices? Give three examples of devices with embedded computers.
(b) Add 11001011 to 10111011and convert your answer to one’s (1’s) complement.
(c) With the use of one example each, differentiate between a command and a statement in BASIC.
5. (a) Explain with examples the following BASIC terms:
I. Variables
II. Reserved words.
III. Identifier.
(b) Write a Basic program to add four numbers, A, B, C, D and display the result.
6. (a) Describe three basic types of translators that you know?
(b) Discuss with examples a categorization of computers according to their modes of operation.
Past Question Introduction to Computer Science
DEPARTMENT OF MATHS/STATISTICS & COMPUTER SCIENCE
CSC 1101 – Introduction to Computer Science 2006/2007 Session
Instructions: Answer all questions Continuous Assessment 2 Time: 30 Mins
1. a. Justify why Charles Babbage is known as the father of modern computer.
b. Despite the cheapness of computer packages, most organizations still prefer customized software.
2. a. What major defects of the first generation computers gave rise to the second generation computers?
b. Mention the two persons who developed ENIAC and the place of development.
3. What are registers, as used in the ALU?
4. a. Why is the Binary number system so important in Computer Science?
b. What two major differences separate Auxiliary memory from Main memory?
Saturday, November 14, 2015
Past Question On File Processing 2013/2014
DEPARTMENT OF MATHS/STATISTICS & COMPUTER SCIENCE
SECOND SEMESTER EXAMINATION 2012/2013
COURSE: CSS 2222 – INTRODUCTION TO FILE PROCESSSING TIME: 3HOURS
INSTRUCTIONS: Answer any four (4) questions with two from each section
SECTION A
1. (a) (i) Discuss freely the concept of computer files and distinguish clearly between logical and physical records. (ii) What is a record key? Discuss its use in file processing.
(b). A magnetic tape that is 25 feet long has 2 feet of unusable portion. If density of this tape is 10 bytes/inches and blocking factor is 5, estimate the number of logical records of record length 95 bytes that can be stored in this tape if inter-block gap is 0.0025 inches.
2. (a) (i) Distinguish clearly a sequential file organization from a serial file organization.
(ii) Distinguish a Direct Access Storage (DASD) from Random Access Method (RAM).
(b) (i) What do you understand by the address of a record in a file? (ii) Describe two methods used to assign addresses to records in a file. (iii) What is file organization?
3. (a) (i) Discuss the storage and retrieval processes of ISAM and sequential file organizations.
(ii) State precisely the facilities in ISAM file organization that are not found in sequential files.
(iii) How do you use the additional facilities in ISAM file organization?
(b) (i) Distinguish between a master file and a transaction file. (ii) Suppose you have a master file M, and a transaction file T, both of which are sequentially sorted. Give an algorithm that uses T to update M in order to get new master NM.
SECTION B
4. (a) Using concrete examples, differentiate between files and directories, stating why each is important in its own right.
(b) In a multiuser system, there is almost always a requirement for allowing file sharing among users, describe any five (5) access rights in the light on this.
5. (a) You have been handed the task of making a small presentation on file allocation schemes at the forthcoming orientation for Computer Science students in our Department. You are to use the following files to demonstrate contiguous allocation: HOD_Admin.xls (length=5), Students.mdb (length=9), AcadStaff.doc (length=5), AdimStaff.pdf (lenth=7) and NUDCB.html (lenth=8) in that order. Starting your allocation at block 2; (i) Show how this allocation will be done on disk (ii) Construct a directory table showing how these files will be allocated.
(b) (i) Sow how the file AdimStaff.pdf will be allocated using chained and indexed allocation schemes, respectively. (ii) Make brief comments on external fragmentation stating why it is prevalent in contiguous allocation.
6. (a) Typical of computer installation management, describe with examples, any three (3) ways in which you can provide file security.
(b) You have been handed four record keys: 876-54-3210, 123-45-6789, 187-65-2243, and 101-20-3037 to place in a database file that contains a maximum of twelve records. Using the modulus hashing technique/algorithm, show how these records will be placed in the file.
Thursday, November 12, 2015
Computer Science Past Questions On Computer Architecture 2012/2013
UNIVERSITY OF CALABAR
DEPARTMENT OF MATHS AND COMPUTER SCIENCE
YEAR 3 EXAMINATIONS 2012/2013
CSC 3321: COMPUTER ARCHITECTURE 1
ANSWER 2 QUESTIONS FROM EACH SECTION TIME 21/2 HRS
SECTION A
1(a) When the computer is running the control unit is doing fetch and execute. Name
the three cases of the execute phase.
(b) Explain how information is stored and how it is retrieved.
(c) Differentiate active retrieval from passive retrieval of information.
Also Read: Computer Science Past Question On Computer Laboratory 2012/2013
2(a) Explain (i) Syllable (ii) Shift-and Count (iii) Overflow (v) Index Register
(b) Explain what a flag is; and name five flags-giving their functions.
(c) How is overflow detected and how is it corrected?
(d) Name and explain the three microprocessor instruction formats.
Also Read: Past Questions On Introduction To Basic Programming 2011/2012
3(a) Name the four things involved in operations and processes in computing.
(b) Name and explain five control instructions.
(c) When does system interrupt occur?
(d) Name five typical instruction types that involve stores and registers, and state the
lengths of the instructions.
Also Read: Past Questions On Introduction To Computer Science CSC1101 2011/2012
(b) Comment briefly on the limitations of manual computation known to you
(c) Discuss the factors that can lead to high performance of a computer architecture
Also Read: Past Question On Computer Systems 2012/2013
2 (a) With the aid of suitable diagrams differentiate between human and machine
computational architectures
(b) Every computer human or machine must have a set of components, comment
briefly on these components stating clearly their functions.
(c) Suppose that an algorithm A is to be executed by a computer. Two questions can
be raised concerning the difficulty of the algorithm. Comment briefly on these questions.
Also Read: Past Question On Computer Systems 2011/2012
3 (a) With the aid of a simple diagram discuss the architecture of Charles Babbage analytical
Engine.
(b) Describe the function of the following instruction set of the IAS computer.
(i) MQ ← M(X)
(ii) AC ← AC + M(X)
(iii) AC.MQ ← MQ X M(X)
(iv) AC ← AC – M(X)
(v) AC ← AC + I M(X)I
(c) Explain the function(s) of the following in S/360-370 computer
(i) R.R
(ii) RX
(iii) RS
(Iv) SI
(v) SS
Computer Science Past Question On Computer Laboratory 2012/2013
DEPARTMENT OF MATHS/STATS & COMPUTER SCIENCE
SECOND SEMESTER EXAMINATION 2012/2013 SESSION
COURSE CODE: CSC 3381
COURSE TITLE: COMPUTER LAB III A TIME: 1Hr 30mins.
INSTRUCTION: ANSWER ANY TWO QUESTIONS IN SECTION A. SECTION B IS COMPULSORY
1. a. What are data types? Using C or C++ syntax, declare variables of three different types.
b. What are Control Structures? Mention and discuss any two in C or C++.
c. Write a C or C++ function and main program to produce prime numbers to a given n.
2. a. What is an array? Declare an array of 30 characters and a pointer to the array in C or C+++.
b. Explain four keywords associated with data output in C/C++.
c. Write a C or C++ function and main program to produce the Greatest Common Divisor for any
given integers P and Q.
3. a. What are preprocessor directives? List five and state their uses.
b. Compare the use of scanf and cin in C and C++ respectively.
c. Write a C or C++ function and main program to produce the Factorial of any given integer n.
4. a. What are pointers? Declare a pointer to a char type variable.
b. Compare the use of printf and cout in C and C++ respectively.
c. Write a C or C++ function and main program to produce the Fibonacci numbers to any
given integer n. (where n>1)
1 | #include <stdio.h> |
Questions
1. Number and explain what each line of the code above does.
2. Discuss the kernel of the While loop with an execution frame.
3. What is the entire program doing?
4. Is this program a C or a C++ convention? Hence what changes would make it C or C++
C++ Program to Find Prime Number Or Not
#include <iostream.h>
#include <math.h>
void main()
{
int num, a=0;
cout<<"enter a number: ";
cin>>num;
for(int i=2;i<num;i++)//loop begins at 2 since 1 can divide any number
{
if(num%i==0)
{
a++;
}
}
if(a==0)
{
cout<<num<<" is a prime number";
}
else
cout<<num<<"is not a prime";
}
Wednesday, November 11, 2015
Find The Perfect Number In C++ Program
For example 28 a Perfect Number since the sum of its divisors which are 1+ 2 + 4 + 7 + 14 = 28
Also Read: C++ Program To Find Roots Of a Quadratic Equation
#include<iostream.h>
#include<math.h>
int main()
{
int i,n,sum=0;
cout<<"enter a number";
cin>>n;
for (i=1;i<n;i++)
{
if(n%i==0)
sum=sum+i;
}
if(sum==n)
cout<<i<<"is a perfect number";
else
cout<<i<<"is not a perfect number";
return 0;
}
Also Read: C++ Program To Find Prime Numbers
Past Question On Computer Systems 2012/2013
UNIVERSITY OF CALABAR
FIRST SEMESTER EXAMINATION – 2012/2013 SESSION
CSC 2221 – INTRODUCTION TO COMPUTER SYSTEMS
TIME : 3HRS INSTRUCTION : ANSWER QUESTION ONE AND ANY OTHER THREE
1. (a) (i) What is the mathematical relationship between digits of a number system.
(ii) What is a compiler and what are their importance.
(ii) Describe the booting process.
(b) (i) Convert 10 Gigabyte to bits.
(ii) Divide 1000110 by 110 and 110100 by 100
(iii) Convert the following decimal numbers to binary: 3323.15 and 2882.75
(c) Use one’s and two’s complement to perform the operations: (i) 28 – 7 (ii) 110 – 25
(d) Discuss units of computer storages in the range 0 to 1050.
2. (a) Classify and explain software.
(b) Add all at once: 110111, 10111.11, 111.01, 1110, 11011.01, 0.111.
(c) Perform the following Hexadecimal arithmetic: 951ACD + 3ABC and AA989 - 1BDF
3. (a) Discuss the block representation of the computer fully.
(b) Evaluate: 134Ah divided By, 45CDh * 6h
4. (a) The following are numbers in Sign Magnitude Representation: 11101110111010, 1110101001.Produce their Hex, Octal and decimal equivalent.
(b) Highlight the functions of different memory types in the computer system.
(c) Perform the following Quinary arithmetic: 33421+43211 and 44321 – 3344
5. (a) Convert alphanumeric number PIZZA and FIFA to decimal.
(b) Convert vigesimal numbers ICED and CCDI to decimal.
(c) Perform the following hexadecimal arithmetic: 93A40 – 8ADF and BCA0 * 9A
6. (a) Using one and two’s complement perform: 12 – 23 and 13 – 8
(b) Convert the following octal numbers to tenary: 34730 and 6400.
(c) Perform the following binary division: 1100100001/110 and 1110001 by
Past Question On Computer Systems 2011/2012
UNIVERSITY OF CALABAR
FIRST SEMESTER EXAMINATION – 2011/2012 SESSION
CSC 2221 – INTRODUCTION TO COMPUTER SYSTEMS
TIME: 3HRS INSTRUCTION: ANSWER QUESTION ONE AND ANY OTHER THREE
1. (a) How does the CPU cope with the memory and I/O units considering speed differences. Use diagram to clarify your explanation.
(b) (i) Convert 3 terabyte to nibbles.
(ii) Divide: 1000110 by 110 and 1101 by 10
(iii) Convert the following decimal numbers to binary: 4623.15 and 3982.75
(c) Use one’s and two’s complement to perform the operations: (i) 20 – 17 (ii) 120 – 55
(d) Usethe stack operation to exchange the contents of AX, BX and CX
2. (a) Classify and explain software
(b) How does the CPU operate in relation to the flags register?
(c) Explain the working of the following assembly language segment. MOV CX,10
MOV AX,0
LOOPBEGIN:ADD AX,CX
SUB CX,I
JNZ LOOPBEGIN
MOV DX,AX
3. (a) Discuss memory hierarchy in the computer system.
(b) (i) How many bit are needed to address one megabyte and how?
(ii) Justify how the CPU carries out 32-bit arithmetic operation with its 16-bit registers.
(c) If the Stack Segment and pointer are set to the values 10002h and 301h. Derive the memory address.
4. (a) Discuss Segment registers.
(b) (i) Explain the operation of Instruction Pointer.
(ii) Derive the contents of AL, BH and CL in the following: MOV AX,10000h
MOV BX, 2ABh
MOV CX,16Ah
(c) (i) Add all at once: 10111, 1011.11, 111, 1110, 11011.01, 0.111
(ii) Using one and two’s complement perform: 12 – 23 and 13 – 8
5. (a) (i) Explain the effect of formatting a disk.
(ii) Categorize/explain Optical Storage devices.
(b) Explain the three ways of representing signed numbers.
(c) Subtract the following hexadecimal numbers: 3A40 – 8A4 and BCA0 – 93A
6. (a) Explain the function of ROM. What are the significance of the different types of ROM?
(b) Convert the following decimal numbers to hexadecimal: 34730 and 6800
(c) Perform the following division: 110010/1110 and 100001 by 10
(d) Evaluate: 4A/A. What is the content of AX and DX register before and after the operation
C++ Program to Find All The Roots Of A Quadratic Equation
A quadratic equation has the form ax^2+bx+c=0 where x is an unknown, and a, b, c represent values which in this c++ program will be supplied by the user.
Also Read: C++ Program To compute least common multiple
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c,d,x1,x2;
cout<<"Enter the value of a: ";
cin>>a;
cout<<"Enter the value of b: ";
cin>>b;
cout<<"Enter value of c: ";
cin>>c;
d=b*b-4*a*c;
if(d==0)
{
x1=(-b)/(2*a);
x2=root1;
cout<<"The Roots are real & equal";
}
else if(d>0)
{
x1=-(b+sqrt(d))/(2*a);
x2=-(b-sqrt(d))/(2*a);
cout<<"the Roots are real & distinct";
}
else
{
x1=(-b)/(2*a);
x2=sqrt(-d)/(2*a);
cout<<"Roots are imaginary";
}
cout<<x1<<" "<<x2;
}
C++ Program to Compute The Least Common Multiple of Integers
//C++ program that computes the least common multiple of two integers. These are represented as a and b below.
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,i,j; //Variable declarations
clrscr;
cout<<"enter a number: ";
cin>>a;
cout<<"enter a number: ";
cin>>b;
i=a ;
j=b;
if(a==0||b==0) //Checks if either a OR b is 0
cout<<" The LCM is 0"; //If 0 from the condition above, a display message is output to the screen
else
{
while(a!=b)//While the value of a is not equal to b execute the statements below
{
if(a>b)
b=b+j;
else
if(a<b)
a=a+i;
}
cout<<"LCM:"<<" "<<a;
}
}
C++ Program to Compare The Greatest Of Three Integers
#include<iostream.h>
#include<math.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
cout<<"enter the first value";
cin>>a;
cout<<"enter the second value";
cin>>b;
cout<<"enter the third value";
cin>>c;
if (a>b&&b>c)
cout<<"The greatest is: "<<a;
else
if(a<b&&b>c)
cout<<"The greatest is: "<<b;
else
if(a<b&&b<c)
cout<<"The greatest is: "<<c;
else
if(a==b&&b==c)
cout<<"Non is greater!!";
}
Pascal Program Calculate The Sum and Average of Ten Positive Numbers
Also Reead:Pascal Program of Matrix Multiplication
Program Arithmetic Operation (Input, Output);
Uses Crt;
Label 5;
Var Sum, Ave, Number: Real;
i: integer;
Begin
5: Writeln ('Enter a number');
Readln (number);
If Number<0 then goto 10
Else
Sum:=Sum+Number;
i:=i +1;
IF i<10 then goto 10;
AVE:= sum/10
Writeln ('sum=', sum);
Writeln ('Average=' , Ave);
Readln;
End.
Line 1 'program' specifies the name of the program. The 'label 5' is a goto statement and also a global identifier. A global identifier is one which is specified at the beginning of the program and can be used anywhere in the program.
The next line 'var' is used to declare our variables which are sum, ave, number before it is used in the program. 'i' is also declared because it will serve as a counter in the program. It will be used to know when the number exceeds ten. 'Begin' signifies the beginning of the program and if you notice a semi colon is not attached to it.
Also Read: C++ Program to Check If a Number Is A Perfect Number or Not
C++ Program to Find All The Roots Of A Quadratic Equation
C++ Program to Compute The Least Common Multiple of Integers
The next line '5' uses the goto statement that was already identified as a label. 'Writeln' is a command that will write a line on the user's screen asking for any random number with the question 'enter a number'. A semicolon is attached to the end showing it is the end of the statement.
'ReadLn' prompts the pascal compiler to read the above statement and identify it as 'number' which we also declared a s a variable. The first IF statement with a goto statement tells the compiler to return to line 5 if the number the user entered was negative which is less than 0. If this number was greater than 0, then the ELSE clause is implemented and the program continues by assigning 'SUM+Number' to 'SUM' which was globally declared at the beginning of the program.
The next line increments our counter by 1 (i+1) such that we will expect the second number to be entered till the tenth number as required by the question. This will be so from the next line IF the counter is less then ten, it should go back to our label 5, which is 'enter a number'. This will continue until the condition (IF i<10 then goto 5) is satisfied by we having ten numbers. It goes on to AVE and calculates the average by the formula from the program which is the total sum of these numbers divided by 10.
The 'writeln' prints the answer to our program on the screen. The answer to sum and average. The program is terminated with 'end.' having a full stop.
Monday, November 9, 2015
Past Question on File Processing CSC 2222
UNIVERSITY OF CALABAR
CALABAR
DEPARTMENT OF MATHEMATICS/STATISTICS/COMPUTER SCIENCE
SECOND SEMESTER EXINATION 2005/2006.
COURSE NO: CSC 2222
1a. Explain the concept of file system within the computer system, pointing out the likely content of each file system. Why do you think a file is important to a computer system?
1b. Using suitable examples, describe any four (4) different types of files, pointing out the content in each case. Is linear list a file? If yes briefly describe what it is.
2a. Distinguish clearly between (i) logical and physical records (ii) sequential and direct storage medium (iii) primary and secondary storage devices.
2b. Describe the advantages of blocking records in a file. A specification is given to a file on magnetic tape as follows : blocking factor is 20; inter-block gap is 1.5cm; Density of tape is 2.5 bytes per inch, usable portion of tape is 24 feet. How many records of fixed length 110 can be stored in this tape?
3a. What do you understand by the term "file organisation"? Discuss the factors you would consider when. Choosing a file organisation.
3b. Discuss the concept of directories in your file system. Explain how you would protect your file(s) from unauthorised users.
SECTION B
4a. State any five (5) operations that can be performed on files. Using sequential file organization for illustration, discuss how three (3) of the operations can be implemented.
5a. Explain any three basic file allocation techniques, giving their respective merits and demerits.
5b. (i) Discuss the concept of random/direct file organisation.
(ii) Explained any two hashing techniques.
6a. Differentiate clearly between (i) linear probing and bucket chaining. (ii) Incremental and full backup.
6b. State any five backup guidelines.
Past Questions On Introduction To Basic Programming 2011/2012
UNIVERSITY OF CALABAR
SECOND SEMESTER EXAMINATION 2011/2012 SESSION
CSC 1182- INTRODUCTION TO BASIC PROG. TIME:1hr.40mins
Instruction: Answer any two questions from section A and All in section B.
Section A. Theory – 40% 1hr
1. Write a BASIC program that allows you find the average score of 5 students offering 5 courses: either (i). Without using IF-THEN statement or (ii). With the use of IF-THEN statement or (ii) Using For-To-Next statement.
(b). Write a BASIC program to produce the first 100 fibonnaci numbers.
2. If a man has 6children and each child scored 5 different marks in 5 different courses, write a BASIC program that will, for each child, find the average mark and print out the result into a text file.
(b). Write a BASIC program that can produce the Greatest Common Divisor (GCD) given two integers.
3. Study the program below and answer the following questions: (i). Draw a flowchart for it
(ii). What will be the output? (iii). Rewrite the program using for next loop.
k=1
40 p=p+k^3-k^2
Print k, p, p^2
k=k+1
If k<=5 THEN 40; 75 GOTO 80 80 END
(b). Write a BASIC program that can produce the Lowest Common Multiple (LCM) given two integers.
4. A class of four students had exams in 4 different courses and performed as follows:
NAMES CSC1102 CSC1182 CSC1352 CSC1241 SAS
PETER 70 60 14 31 ?
JOHN 54 56 62 28 ?
COMFORT 89 82 86 60 ?
CHRISTY 61 90 84 72 ?
CAS ? ? ? ? ?
Write a program to (i) Read in the scores of each student in all the courses. (ii). Sum the total scores of each course and find the class average score (CAS). (iii). Sum the total score of each student and find the student’s average score (SAS).
(b). What is an array?
Section B: Lab section (Alternative to practicals) -60% 40 mins
Study the program below and answer the questions that follows.
1. CLS
2. OPEN”felixp.txt” FOR OUTPUT AS #1
3. INPUT N4. DIM a(N)
5. a(1)=0
6.
7. FOR i= 2 TO N STEP 1
8. a(i)=1
9. NEXT I
10.
11. FOR I = 2 TO N / 2 STEP 1
12. FOR j = 2 TO N / 2 STEP 1
13. a(i*j) = 0
14. NEXT j
15. NEXT i
16.
17. FOR I = 1 TO N STEP 1
18. IF a(i) = 1 THEN PRINT #1, I; “ is a PN “
19. PRINT
20. NEXT i
21.
22. END.
(a). What is the program’s main aim?
(b). Explain what each line of code does.
(c). If the program is ran, what do you expect as the prompt?
(d). Assume you are asked to split this program into sub-routines, how many would you create. Give them arbitrary names.
(e). Prepare an execution frame for lines 11 to 15; given that N is 10.
(f). What is the loop of line 7 to 9 doing to the array a(i)
(g). To what level is the array a(i) different from that of a(i*j) found in lines 8 and 13 respectively.
(h). The array index i is set to 1 in line 8 and that of i*j is set to 0 in line 13, what are the properties of these array indexes?
(i). What is the intention of the construction of the loop of 17 to 20
(j). Having gotten a fair knowledge of the result from the execution frame, whatdo you think PN stands for? Hence if N is given as 10, what would be the first five series of the result.
Past Questions On Introduction To Computer Science CSC1101 2011/2012
DEPARTMENT OF MATHS/STATS. AND COMPUTER SCIENCE
2NDSEMESTER EXAMINATION 2011/2012 CSC1102: INTRO. TO COMPUTER SC. II
INSTRUCTION: ANSWER ANY FOUR QUESTIONS ATLEAST ONE FROM EACH SECTION
TIME:2HOURS
1a. In a class of M students, each student offers N courses. If M=20 and N=5 write a flowchart and a computer program in Basic programming language that will accept the following input data: (i) name of a student. (ii) Matric number of a student. (ii) scores for the N courses. Compute each student average score, and each student is given a pass status if his/her average score is greater than or equal to 50 otherwise the student is given a fail status. Output your result to the screen of the monitor.
1b. Comment briefly on any two control structures you have employed in your computer program in question 1a above.
1c. With the aid of a simple illustration differentiate between counted loop and conditional loop.
2a. Decline the term branching and comment briefly on any two types of branching known to you.
2b. Comment briefly on the various stages of program development known to you.
2ci. Define an array and comment briefly on its major properties.
2cii. Write an interactive basic program that will allow you to generate the elements of a two dimensional array of any data type known to you.
SECTION B
3a. Explain what you understand by the efficiency of algorithm
3b. What makes it necessary to study algorithm as a computer scientist?
3c. What makes an algorithm Z more efficient than another algorithm Y
4a. Consider two computers A and B. Computer A is faster and runs in insertion sort against a slower computer B running merge sort. They each must sort an array of two million JAMB candidates using their registration numbers. Suppose that computer A execute one and a half billion instruction per a second and computer B executes only fifteen million instruction per second. Suppose also that the insertion sort was coded by the best programmer ever, and the merge sort by an amateur programmer. If the code for insertion sort takes 2n2 instructions to sort n numbers and that of takes 65 n log n.
(a). Compute the time it will take computer A to sort the array.
(b). Compute the time it will take for computer B to sort the same array.
(c). Describe the speed of one over the other.
(d). Using the answers in (a) and (b), describe which of the two computers is more efficient, based on the algorithm they run.
SECTION C
5. (a) Give the steps involved in the insertion sort algorithm. Given the elements of the array j: using insertion sort, arrange the following items of the array with the iterator positioned at index 1. 61 48 34 82 48 57 89 45 70
(b). Describe the Bubble sort and Mergesort algorithms giving their worst case computational complexity. Give the general strategy for moving n disks from origin to destination in the Towers of Hanoi game.
