6 views

Uploaded by Lehlohonolo Makoti

save

You are on page 1of 5

**Department of Mathematics and Computer Science
**

CS 2431-Programming Fundamentals

Test 01 - Open Book

28th September 2005

Marks: 100

Time: 2 hours

Instructions:

(1)

(2)

(3)

**Answer any five (5) questions. Each question carries 20 marks.
**

Marks are shown at the end of each (sub)question.

This paper consists of 5 printed pages

Question 1:

a) Define the following terms

i) A computer program

ii) A compiler

iii) An interpreter

.................................................................................................................................. [2+2+2]

b) Write a C++ program or a function that uses a FOR loop to find a product of integer

numbers between any two integers,

(

) with a specified incremental

step, k.

........................................................................................................................................ [14]

Question 2:

a) Identify all syntax errors in the following program

#include <iostream >

int m ain()

{

cout << ‘CS2431 Test 01';

}

.......................................................................................................................................... [9]

b) The computation

, is the arithmetic

, for the integers y

and n.

Write a C++ program or function that uses a WHILE loop to compute

.

........................................................................................................................................ [11]

Question 3:

a) Consider the following program segment

int sum = 0;

for(int k = 1; k <= n; k++)

{

cout << “k = “ << k << “ sum = “ << sum << endl;

sum += k;

}

**Write down the output of this loop for n = 4.
**

CS 2431 - Programming Fundamentals

28th Sep 2005

Test 01

Page -1/5-

............................................. [8] b) A factorial of a natural number n is defined as: Using a DO ..................................................................... Assume that age (type int) and gender (type char) would be used as appropriate variable names................. otherwise it issues Policy B............................ [14] CS 2431 .... [12] Question 4: a) An insurance company issues policies depending on the age and gender of its clients... i < = 3.......... The classification is as follows: Mean Mark Classification 65 or above Pass with Credit 50 – 64 Pass below 50 Fail Using an IF statement construct........................................... The classification is based upon the performance mean mark of the student.......... graduates are classified as “Pass with Credit”................................ ..............e....................................................................................... [2+2+2] b) In a college........ Write a C++ IF statement that could be used for issuing these insurance company policies... write a program or a function that accepts a mean mark (type int) from the user and then outputs the appropriate classification message............................................................................. any arithmetic expression evaluating to a non-zero value is regarded as representing the truth value: true............................... Use the C++ cout statement to print out the appropriate message to issue the corresponding policy............. “Pass” or “Fail”.......................................Programming Fundamentals 28th Sep 2005 Test 01 Page -2/5- .............. j++) cout << i << “ ” << j << “ ” << i * j. the company issues Policy A (i......... the most attractive package)...... .......................................................................................... WHILE loop write a program or a function computing n! .. ............ If the client is female and below 40 years of age..................................................................... [10] Question 5: a) Say whether true (T) or false (F) in the following i) A C++ variable can be an underscore character ii) In C++..... j < = i................ iii) The two Boolean constants: true or false are integer expressions...... [10] b) Write down the output for the following nested FOR loop for( int i = 1................. ........................................................... i++) for( int j = 1.

The program then displays the classification of the student based on the calculated OWM and the given classification rules.. The program then allows the user to enter course information for the next student or quit the program........................................ Second Division 50 – 59 Pass 0 – 49 Fail Write a C++ program or function that can classify students at NUL as follows: 1....... 3......... except the least prime......Programming Fundamentals 28th Sep 2005 Test 01 Page -3/5- ... The program then outputs a message whether N is prime or that N is not prime HINT: 1.......................... [20] Question 7: At NUL students are assessed and classified based upon an individual’s overall weighted mean (OWM) which is computed as: The classification is as follows: OWM Classification 75 or above First Class 70 – 74 Second Class..................... [20] CS 2431 ..... All primes are odd.............. 2....... ...... meaning N mod p = 0.. .. 2.......................... N is not prime iff such that p is a co-factor of N.. 3... The program accepts a number............... ............................................ until the user has finished all the courses for this particular student......................... N.... 2..... First Division 60 – 69 Second Class......Question 6: Write a C++ program or function that can determine if the given number is prime or not as follows: 1.... from the user 2... Every non-prime number N can be written as a product of its prime factors only.. The program allows the user to enter each course mark (type int) and its corresponding credit hours (type int) a pair at the time........

CS 2431 .Programming Fundamentals 28th Sep 2005 Test 01 Page -4/5- .

Programming Fundamentals 28th Sep 2005 Test 01 Page -5/5- .CS 2431 .

- 07 Advanced RTF Template TechniquesUploaded bynalin_rastogi9689
- EXCEPTION HANDLINGUploaded byAnonymous 2oUJOl3rRt
- 1.1_Introduction to JavascriptUploaded byshrygpta
- Notes for c Language Part 1Uploaded byAsh ShOck
- LoanUploaded byLorie Ann Olivario
- Lecture 2Uploaded byMina Fawzy
- Manual # 2Uploaded bymusa
- Apress.salesforce.com.Lightning.process.builder.and.Visual.workflow.1484216903Uploaded bySimon
- Excel Efficiency TipsUploaded bypinku_malhotra007
- Programming Language BUploaded bylutyouste
- LearnersUploaded byManjunath Reddy
- 41319990_Assignment02_Semester02Uploaded byBra Plengo
- ConditionalUploaded byRachee Marañon
- t05BProgramControlAlgorithmsUploaded byPavitha Guru G
- CZ1102 Computing & Problem Solving Lecture 3Uploaded byCharmaine Chu
- SIMATIC - S7-Net FreewareUploaded byJorge Andril
- tcs cUploaded byparanitk
- Lecture Notes for Embedded ControllersUploaded byJorge Peralta
- Common Language RuntimeUploaded byShiju Nadar
- Simple JavapgmsUploaded byKarunakar Ella
- 4 Flow Control , Exception , AssertionsUploaded byapi-3833545
- 28Uploaded byDonweriyal
- Class2 Visual Basic Statements and ExpressionsUploaded byhanamsaleh
- CLess 19 DatatyUploaded bySmita R. S.
- Exercises SolvedUploaded byMangeshRudrawar
- Unit3Uploaded byPooja Bk
- Introduction to MatlabUploaded byEvans Krypton Sowah
- InputStream (Java Platform SE 7 )Uploaded bypcdproyecto
- Lesson 2 - Variables and Data TypeUploaded byJohn Son
- Basic Java Programs (3)Uploaded byanil

- 07 Advanced RTF Template TechniquesUploaded bynalin_rastogi9689
- EXCEPTION HANDLINGUploaded byAnonymous 2oUJOl3rRt
- 1.1_Introduction to JavascriptUploaded byshrygpta
- Notes for c Language Part 1Uploaded byAsh ShOck
- LoanUploaded byLorie Ann Olivario
- Lecture 2Uploaded byMina Fawzy
- Manual # 2Uploaded bymusa
- Apress.salesforce.com.Lightning.process.builder.and.Visual.workflow.1484216903Uploaded bySimon
- Excel Efficiency TipsUploaded bypinku_malhotra007
- Programming Language BUploaded bylutyouste
- LearnersUploaded byManjunath Reddy
- 41319990_Assignment02_Semester02Uploaded byBra Plengo
- ConditionalUploaded byRachee Marañon
- t05BProgramControlAlgorithmsUploaded byPavitha Guru G
- CZ1102 Computing & Problem Solving Lecture 3Uploaded byCharmaine Chu
- SIMATIC - S7-Net FreewareUploaded byJorge Andril
- tcs cUploaded byparanitk
- Lecture Notes for Embedded ControllersUploaded byJorge Peralta
- Common Language RuntimeUploaded byShiju Nadar
- Simple JavapgmsUploaded byKarunakar Ella
- 4 Flow Control , Exception , AssertionsUploaded byapi-3833545
- 28Uploaded byDonweriyal
- Class2 Visual Basic Statements and ExpressionsUploaded byhanamsaleh
- CLess 19 DatatyUploaded bySmita R. S.
- Exercises SolvedUploaded byMangeshRudrawar
- Unit3Uploaded byPooja Bk
- Introduction to MatlabUploaded byEvans Krypton Sowah
- InputStream (Java Platform SE 7 )Uploaded bypcdproyecto
- Lesson 2 - Variables and Data TypeUploaded byJohn Son
- Basic Java Programs (3)Uploaded byanil
- What is an InquestUploaded bypelican101306
- rematik.docUploaded byAde Putri Radiana
- [Karl_A._Menninger]_Man_Against_Himself(b-ok.xyz).pdfUploaded byJan Cesar Olaya Correa
- CCNAquestions_Jun_2018.pdfUploaded byGhayas Ali
- privacy notice- parents and carersUploaded byapi-346489839
- Ryff.pdfUploaded byLizette Mendivil
- PhilHealth_ClaimForm1Uploaded byhazel mabaso
- PREVIOS 1° VESPERTINOUploaded bymaricelmaffrand
- Graficas IntegralUploaded byAldair Ramos Ortiz
- CliveUploaded bycharlotte anne vinuya
- Chittister Joan La Vida Iluminada (1)Uploaded byJaviera Lubascher Díaz
- kandunganUploaded byYudha Pradikta
- Tugas Minggu 11 - Aspek SDM - Kelompok 12 RALSUploaded byAby Huzai
- Hukum Acara Peradilan PerdataUploaded byYehuda Pramana
- 6-pembelahansel.pptUploaded byAndi Debron
- Perkins serie 2800.pdfUploaded byKevin Herrera Murgas
- accouplements_ d_arbres.pdfUploaded bydieslen
- CELEX_32009R0715_BG_TXTUploaded bydonla15
- El Diario 04/12/18Uploaded byEl Diario de Paraná
- Certificado FONASAUploaded byPato Flores
- 2012 3 Series f30 Order GuideUploaded byFabian Luca
- Acreditivul15Uploaded byMarius Guta
- modelo_de_curriculo_senac.pdfUploaded byreal bas
- arte-y-clases-sociales-vermeer-y-meunier.pdfUploaded byBeluga79
- katalog (1)Uploaded bykondicm88
- ART oficial Vita & salute.pdfUploaded byRafael Marques
- Imey Bangga Jadi Burung Bangau_LoriUploaded byChristine Gloriani
- ritornelo.pdfUploaded byAnonymous uuV9d4r3
- 6-PEND.-BHS.-IND-2013Uploaded byArga Haphe Pratama
- Regolamento Tattuatori Regione FriuliUploaded byAndrea Veg