SlideShare ist ein Scribd-Unternehmen logo
1 von 12
Downloaden Sie, um offline zu lesen
CPPH501 – PAPER A. (2019 S1)
1
YEAR:
Student Number
Surname & Initials
2019
SEMESTER:
ASSESSMENT:
1
A
SUBJECT NAME: Computer Programming 1
SUBJECT CODE: CPPH501
QUALIFICATION(S): D3IP13 /INDUSTRIAL PHYSICS
PAPER DESCRIPTION: COMPUTER
BASED
DURATION: 3 HOURS PAPER: ONLY
SPECIAL REQUIREMENTS
 NONE
 NON-PROGRAMMABLE POCKET CALCULATOR
 SCIENTIFIC CALCULATOR
 COMPUTER ANSWER SHEET
 GRAPH PAPER
 DRAWING INSTRUMENTS
OTHER: COMPUTER
INSTRUCTIONS TO CANDIDATES: ANSWER ALL QUESTIONS
THIS TEST IS TO BE ANSWERED ON https://mytutor.tut.ac.za
WHEN YOU ARE DONE. GIVE YOUR ANSWER SCRIPT BACK TO THE
INVIGILATOR AND SUBMIT YOUR FILE.
TOTAL NUMBER OF PAGES INCLUDING COVER PAGE: 12
TOTAL NUMBER OF ANNEXURES: 0
EXAMINER: W BHEBE FULL MARKS: 96
MODERATOR: A KHOZA TOTAL MARKS: 96
STUDENT TOTAL: ___
STUDENT %: ___
Tshwane Universit)
of Technology
CPPH501 – PAPER A. (2019 S1)
2
QUESTION 1 [10]
STATEMENT TRUE FALSE
Theory
1.1 The float and double data types in C++ store real numbers.
1.2 The condition in the selection structure specifies the decision you are
making and is phrased so that it results in either a true or false answer
only.
1.3 The repetition structure is used to repeatedly process one or more
program instructions until some condition is met, at which time the
structure ends.
1.4 A function header in a C++ program does not end with a semicolon.
1.5 You cannot include actual arguments when you call a void function.
1.6 A repetition structure can only include one instruction.
1.7 To use the predefined function sqrt(), the program must include
the header file cmath.
1.8 The output of the statement:
cout << pow(3.0, 2.0) + 5 << endl; is 14.
1.9 The following is an example of a valid function prototype:
void calc(double, double, double &, double &);
1.10 The built-in srand function is an example of a value-returning
function.
CPPH501 – PAPER A. (2019 S1)
3
QUESTION 2 [10]
In each of the following statements, choose the only correct answer.
2.1 The ____ structure makes a decision and then takes an appropriate action based on
that decision
a. selection
b. case
c. repetition
d. iteration
e. None of the above
2.2 ____ is an example of a syntax error.
a. cout<<’Hello’;
b. cin>>raiseRate;
c. cout<<”New Pay :”<<newPay<<endl;
d. average =number1 +number2/2;
e. None of the above
2.3 The ____ statement tells the computer to leave the switch statement at that point.
a. break
b. continue
c. stop
d. case
e. None of the above
2.4 If the default clause is not the last clause in the switch statement, you will need to
Include a ____ statement at the end of the clause to stop the computer from
processing the instructions in the next case clause.
.
a. continue
b. break
c. stop
d. switch
e. None of the above
2.5 A loop that processes its instructions indefinitely is referred to as a(n) ____ loop.
a. infinite
b. non sentinel
c. accumulating
d. incorrect
e. None of the above
CPPH501 – PAPER A. (2019 S1)
4
2.6 Every C++ program contains at least one function: ____.
a. main()
b. pow()
c. return()
d. rand()
e. None of the above
2.7 In standard C++, the random number generator is a built-in function named ____.
a. rand()
b. random()
c. rnd()
d. rndm()
e. None of the above
2.8 When a function definition appears below the main () function, you must enter a
function ____ above the main() function.
a. argument
b. parameter
c. prototype
d. declaration
e. None of the above
2.9 To pass a variable by reference in C++, you include a (n) ____ before the name of
the corresponding formal parameter in the receiving function’s header.
a. *
b. @
c. #
d. &
e. None of the above
2.10 ____ is an example of a valid function call.
a. void calc(double, double, double &, double &);
b. calc(salary, raiseRate, raise, newSalary);
c. void calc(double current, double rate, double &increase, double &pay)
d. calc(salary, raiseRate, &raise, &newSalary);
e. None of the above
CPPH501 – PAPER A. (2019 S1)
5
QUESTION 2 (MULTIPLE CHOICE)
2.1 a b c d e
2.2 a b c d e
2.3 a b c d e
2.4 a b c d e
2.5 a b c d e
2.6 a b c d e
2.7 a b c d e
2.8 a b c d e
2.9 a b c d e
2.10 a b c d e
CPPH501 – PAPER A. (2019 S1)
6
QUESTION 3 [21]
3.1 What is an escape character? Give an example. [2]
3.2 Propose an appropriate prototype of a function that will return the higher of any two
numbers passed as argument to the function [4]
3.3. Write C++ statements for the following: [3]
𝑝𝑝 = �𝑎𝑎2 + 𝑏𝑏2
CPPH501 – PAPER A. (2019 S1)
7
3.4. Write C++ statements for the following: [3]
𝑠𝑠𝑠𝑠𝑠𝑠 =
𝑎𝑎(𝑟𝑟𝑛𝑛
− 1)
𝑟𝑟 − 1
3.5 Explain in your own words, the term ‘modularity’ [3]
CPPH501 – PAPER A. (2019 S1)
8
3.6 Study the following code and rewrite the program using a “for” loop [6]
Write your answer in the space provided below
int number = 1;
do
{
cout << number <<
endl; number++;
} while (number <= 10);
CPPH501 – PAPER A. (2019 S1)
9
QUESTION 4 [16]
Create a program that displays a series of the first 10 Fibonacci numbers (1, 1, 2, 3, 5, 8,
13, 21, 34, and 55). Notice that, beginning with the third number in the series, each
Fibonacci number is the sum of the prior two numbers. In other words, 2 is the sum of 1
plus 1, 3 is the sum of 1 plus 2, 5 is the sum of 2 plus 3, and so on. Write two versions of
the code: one using the for statement and the other using the while statement. Enter
the C++ instructions into a source file named Question5.cpp. Add appropriate comments
and any additional instructions required to execute your program. Note: the Fibonacci
numbers should appear twice on the screen. Refer to figure 4.1 for sample output.
Figure 4.1
QUESTION 5 [6]
Write a C++ for loop that will produce the output in figure 5.1. Include appropriate
comments and any additional instructions required to execute your program.
Figure 5.1
I C:Usersraphirits.TUTD~sktopSickT~st2D~bugSickT~st2.~x~
i s playing t e the FIRST 10 i onacci
umbers us ing [for s tatement]
i s playing the the FIRST 10 Fibonacci
umbers us ing [while s t a tement]
any key to continue . . . _
Squat'e
4
16
36
64
100
any key
Cube
8
64
216
512
1000
to continue
V
CPPH501 – PAPER A. (2019 S1)
10
Question 6 [23]
Create a program for the sales manager at Computer Haven, a small business that offers
motivational seminars to local companies. Table 6-1 shows the charge for attending a
seminar. Notice that the charge per person depends on the number of people the company
registers. For example, the cost for four registrants is R5 761.32; the cost for two registrants
is R4 321.0. The program should allow the sales manager to enter the number of registrants
for as many companies as needed. When the sales manager has finished entering the data,
the program should calculate and display the total number of people registered, the total
charge for those registrants, and the average charge per registrant. For example, if one
company registers four people and another company registers two people, the total number
of people registered is six, the total charge is R10 082.32, and the average charge per
registrant is R1680.38.
Number of people a
company registers
Charge per person (R)
1 – 3 2160.50
4 – 9 1440.33
10 or more 1296.30
Table 6.1
Include necessary statements to compile and run your program. See figure 6.1 for sample
output.
CPPH501 – PAPER A. (2019 S1)
11
Figure 5-1
QUESTION 7 [10]
Write, compile and run a C++ program to input the following values into an array
named velocity: 10.95, 16.32, 12.14, 8.33, 45.20, 36.45, 7.89, 12.35 and 11.54.
After your data has been entered have your program display the values.
first coApany (negative nuAber to stop the prograA): 4
registered by the next coApany (negative nuAber to stop the prograA): 2
registered by the next coApany (negative nuAber to stop the prograA): -5
otal nuAber of registrants: 6
otal charge for all registrants: R10082.32
uerage charge per registrant: R1680.39
registered by the next COApany (negative
registered by the next COApany (negative
registered by the next COApany (negative
registered by the next COApany (negative
registered by the next COApany (negative
registered by the next COApany (negative
registered by the next COApany (negative
registered by the next COApany (negative
registered by the next COApany (negative
otal nuAber of registrants: 50
otal charge for all registrants: R?561?.39
verage charge per registrant: R1512.35
nm11ber to stop the pl"Ogl"aA): 8
nm11ber to stop the pl"Ogl"aA): 3
nm11ber to stop the pl"Ogl"aA): 1
nm11ber to stop the pl"Ogl"aA): 3
nm11ber to stop the pl"Ogl"aA): 4
nm11ber to stop the pl"Ogl"aA): ?
nm11ber to stop the pl"Ogl"aA): 10
nm11ber to stop the pl"Ogl"aA): 9
nm11ber to stop the pl"Ogl"aA): -1
y
CPPH501 – PAPER A. (2019 S1)
12
INSTRUCTIONS TO STUDENTS
- All codes must be copied into a single file (MS word file, or any other format
recommended by the lecturer)
- The file name must match your student number
- Student name and student number must be written at the top of the submitted file!!
- All practical work must be submitted on myTutor
- Make sure the lecturer or invigilator has collected your project before leaving the
venue!

Weitere ähnliche Inhalte

Was ist angesagt?

B.Com 1year Lab programs
B.Com 1year Lab programsB.Com 1year Lab programs
B.Com 1year Lab programsPrasadu Peddi
 
VTU 1ST SEM PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...
VTU 1ST SEM  PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...VTU 1ST SEM  PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...
VTU 1ST SEM PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...vtunotesbysree
 
Pointers in Programming
Pointers in ProgrammingPointers in Programming
Pointers in ProgrammingHamadZia1
 
C programming 28 program
C programming 28 programC programming 28 program
C programming 28 programF Courses
 
Simple c program
Simple c programSimple c program
Simple c programRavi Singh
 
C - Programming Assignment 1 and 2
C - Programming Assignment 1 and 2C - Programming Assignment 1 and 2
C - Programming Assignment 1 and 2Animesh Chaturvedi
 
important C questions and_answers praveensomesh
important C questions and_answers praveensomeshimportant C questions and_answers praveensomesh
important C questions and_answers praveensomeshpraveensomesh
 
C language questions_answers_explanation
C language questions_answers_explanationC language questions_answers_explanation
C language questions_answers_explanationsrinath v
 
Data structures question paper anna university
Data structures question paper anna universityData structures question paper anna university
Data structures question paper anna universitysangeethajames07
 
C program report tips
C program report tipsC program report tips
C program report tipsHarry Pott
 
Lab. Programs in C
Lab. Programs in CLab. Programs in C
Lab. Programs in CSaket Pathak
 
Itp practical file_1-year
Itp practical file_1-yearItp practical file_1-year
Itp practical file_1-yearAMIT SINGH
 
Few Operator used in c++
Few Operator used in c++Few Operator used in c++
Few Operator used in c++sunny khan
 

Was ist angesagt? (20)

B.Com 1year Lab programs
B.Com 1year Lab programsB.Com 1year Lab programs
B.Com 1year Lab programs
 
VTU 1ST SEM PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...
VTU 1ST SEM  PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...VTU 1ST SEM  PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...
VTU 1ST SEM PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...
 
Pointers in Programming
Pointers in ProgrammingPointers in Programming
Pointers in Programming
 
C lab-programs
C lab-programsC lab-programs
C lab-programs
 
week-3x
week-3xweek-3x
week-3x
 
C programming 28 program
C programming 28 programC programming 28 program
C programming 28 program
 
Simple c program
Simple c programSimple c program
Simple c program
 
C - Programming Assignment 1 and 2
C - Programming Assignment 1 and 2C - Programming Assignment 1 and 2
C - Programming Assignment 1 and 2
 
I PUC CS Lab_programs
I PUC CS Lab_programsI PUC CS Lab_programs
I PUC CS Lab_programs
 
important C questions and_answers praveensomesh
important C questions and_answers praveensomeshimportant C questions and_answers praveensomesh
important C questions and_answers praveensomesh
 
C Programming
C ProgrammingC Programming
C Programming
 
C language questions_answers_explanation
C language questions_answers_explanationC language questions_answers_explanation
C language questions_answers_explanation
 
Lab 1
Lab 1Lab 1
Lab 1
 
Data structures question paper anna university
Data structures question paper anna universityData structures question paper anna university
Data structures question paper anna university
 
C program report tips
C program report tipsC program report tips
C program report tips
 
Lab. Programs in C
Lab. Programs in CLab. Programs in C
Lab. Programs in C
 
CP Handout#4
CP Handout#4CP Handout#4
CP Handout#4
 
Lab manualsahu[et&amp;t]
Lab manualsahu[et&amp;t]Lab manualsahu[et&amp;t]
Lab manualsahu[et&amp;t]
 
Itp practical file_1-year
Itp practical file_1-yearItp practical file_1-year
Itp practical file_1-year
 
Few Operator used in c++
Few Operator used in c++Few Operator used in c++
Few Operator used in c++
 

Ähnlich wie Cpph exam a_2019_s1

COMP 122 Entire Course NEW
COMP 122 Entire Course NEWCOMP 122 Entire Course NEW
COMP 122 Entire Course NEWshyamuopeight
 
Mid term sem 2 1415 sol
Mid term sem 2 1415 solMid term sem 2 1415 sol
Mid term sem 2 1415 solIIUM
 
c++ Question
c++  Questionc++  Question
c++ QuestionHamza4467
 
By Analyzing and Utilizing Jean Watson theory of caring, creat
By Analyzing and Utilizing Jean Watson theory of caring, creatBy Analyzing and Utilizing Jean Watson theory of caring, creat
By Analyzing and Utilizing Jean Watson theory of caring, creatTawnaDelatorrejs
 
Comp 122 lab 3 lab report and source code
Comp 122 lab 3 lab report and source codeComp 122 lab 3 lab report and source code
Comp 122 lab 3 lab report and source codepradesigali1
 
1 University of Leeds School of Computing Proced.docx
1 University of Leeds       School of Computing Proced.docx1 University of Leeds       School of Computing Proced.docx
1 University of Leeds School of Computing Proced.docxjeremylockett77
 
Spring 2014 CSCI 111 Final exam of 1 61. (2 points) Fl.docx
Spring 2014 CSCI 111 Final exam   of 1 61. (2 points) Fl.docxSpring 2014 CSCI 111 Final exam   of 1 61. (2 points) Fl.docx
Spring 2014 CSCI 111 Final exam of 1 61. (2 points) Fl.docxrafbolet0
 
1-Base-CaseTool KitChapter 11112118Note Calculations are automa
1-Base-CaseTool KitChapter 11112118Note Calculations are automa1-Base-CaseTool KitChapter 11112118Note Calculations are automa
1-Base-CaseTool KitChapter 11112118Note Calculations are automaMartineMccracken314
 
1-Base-CaseTool KitChapter 11112118Note Calculations are automa
1-Base-CaseTool KitChapter 11112118Note Calculations are automa1-Base-CaseTool KitChapter 11112118Note Calculations are automa
1-Base-CaseTool KitChapter 11112118Note Calculations are automaAbbyWhyte974
 
Sample Program file class 11.pdf
Sample Program file class 11.pdfSample Program file class 11.pdf
Sample Program file class 11.pdfYashMirge2
 
LAB_MANUAL_cpl_21scheme-2.pdf
LAB_MANUAL_cpl_21scheme-2.pdfLAB_MANUAL_cpl_21scheme-2.pdf
LAB_MANUAL_cpl_21scheme-2.pdfRavinReddy3
 
Pseudocode algorithim flowchart
Pseudocode algorithim flowchartPseudocode algorithim flowchart
Pseudocode algorithim flowchartfika sweety
 
EC6612 VLSI Design Lab Manual
EC6612 VLSI Design Lab ManualEC6612 VLSI Design Lab Manual
EC6612 VLSI Design Lab Manualtamil arasan
 
Capital budgeting techniques
Capital budgeting techniquesCapital budgeting techniques
Capital budgeting techniquesIan Isabel
 
M150 A Fall2010 T01
M150 A Fall2010 T01M150 A Fall2010 T01
M150 A Fall2010 T01abdalodainat
 
Important C program of Balagurusamy Book
Important C program of Balagurusamy BookImportant C program of Balagurusamy Book
Important C program of Balagurusamy BookAbir Hossain
 
CBCS 2018 Scheme I sem Lab Manual for 18CPL17
CBCS 2018 Scheme I sem Lab Manual for 18CPL17 CBCS 2018 Scheme I sem Lab Manual for 18CPL17
CBCS 2018 Scheme I sem Lab Manual for 18CPL17 manjurkts
 
Bis 311 final examination answers
Bis 311 final examination answersBis 311 final examination answers
Bis 311 final examination answersRandalHoffman
 
C Programming Lab manual 18CPL17
C Programming Lab manual 18CPL17C Programming Lab manual 18CPL17
C Programming Lab manual 18CPL17manjurkts
 

Ähnlich wie Cpph exam a_2019_s1 (20)

COMP 122 Entire Course NEW
COMP 122 Entire Course NEWCOMP 122 Entire Course NEW
COMP 122 Entire Course NEW
 
Mid term sem 2 1415 sol
Mid term sem 2 1415 solMid term sem 2 1415 sol
Mid term sem 2 1415 sol
 
c++ Question
c++  Questionc++  Question
c++ Question
 
By Analyzing and Utilizing Jean Watson theory of caring, creat
By Analyzing and Utilizing Jean Watson theory of caring, creatBy Analyzing and Utilizing Jean Watson theory of caring, creat
By Analyzing and Utilizing Jean Watson theory of caring, creat
 
Comp 122 lab 3 lab report and source code
Comp 122 lab 3 lab report and source codeComp 122 lab 3 lab report and source code
Comp 122 lab 3 lab report and source code
 
1 University of Leeds School of Computing Proced.docx
1 University of Leeds       School of Computing Proced.docx1 University of Leeds       School of Computing Proced.docx
1 University of Leeds School of Computing Proced.docx
 
Spring 2014 CSCI 111 Final exam of 1 61. (2 points) Fl.docx
Spring 2014 CSCI 111 Final exam   of 1 61. (2 points) Fl.docxSpring 2014 CSCI 111 Final exam   of 1 61. (2 points) Fl.docx
Spring 2014 CSCI 111 Final exam of 1 61. (2 points) Fl.docx
 
1-Base-CaseTool KitChapter 11112118Note Calculations are automa
1-Base-CaseTool KitChapter 11112118Note Calculations are automa1-Base-CaseTool KitChapter 11112118Note Calculations are automa
1-Base-CaseTool KitChapter 11112118Note Calculations are automa
 
1-Base-CaseTool KitChapter 11112118Note Calculations are automa
1-Base-CaseTool KitChapter 11112118Note Calculations are automa1-Base-CaseTool KitChapter 11112118Note Calculations are automa
1-Base-CaseTool KitChapter 11112118Note Calculations are automa
 
Sample Program file class 11.pdf
Sample Program file class 11.pdfSample Program file class 11.pdf
Sample Program file class 11.pdf
 
LAB_MANUAL_cpl_21scheme-2.pdf
LAB_MANUAL_cpl_21scheme-2.pdfLAB_MANUAL_cpl_21scheme-2.pdf
LAB_MANUAL_cpl_21scheme-2.pdf
 
Pseudocode algorithim flowchart
Pseudocode algorithim flowchartPseudocode algorithim flowchart
Pseudocode algorithim flowchart
 
EC6612 VLSI Design Lab Manual
EC6612 VLSI Design Lab ManualEC6612 VLSI Design Lab Manual
EC6612 VLSI Design Lab Manual
 
Capital budgeting techniques
Capital budgeting techniquesCapital budgeting techniques
Capital budgeting techniques
 
M150 A Fall2010 T01
M150 A Fall2010 T01M150 A Fall2010 T01
M150 A Fall2010 T01
 
Cp manual final
Cp manual finalCp manual final
Cp manual final
 
Important C program of Balagurusamy Book
Important C program of Balagurusamy BookImportant C program of Balagurusamy Book
Important C program of Balagurusamy Book
 
CBCS 2018 Scheme I sem Lab Manual for 18CPL17
CBCS 2018 Scheme I sem Lab Manual for 18CPL17 CBCS 2018 Scheme I sem Lab Manual for 18CPL17
CBCS 2018 Scheme I sem Lab Manual for 18CPL17
 
Bis 311 final examination answers
Bis 311 final examination answersBis 311 final examination answers
Bis 311 final examination answers
 
C Programming Lab manual 18CPL17
C Programming Lab manual 18CPL17C Programming Lab manual 18CPL17
C Programming Lab manual 18CPL17
 

Kürzlich hochgeladen

Module for Grade 9 for Asynchronous/Distance learning
Module for Grade 9 for Asynchronous/Distance learningModule for Grade 9 for Asynchronous/Distance learning
Module for Grade 9 for Asynchronous/Distance learninglevieagacer
 
Exploring Criminology and Criminal Behaviour.pdf
Exploring Criminology and Criminal Behaviour.pdfExploring Criminology and Criminal Behaviour.pdf
Exploring Criminology and Criminal Behaviour.pdfrohankumarsinghrore1
 
Dr. E. Muralinath_ Blood indices_clinical aspects
Dr. E. Muralinath_ Blood indices_clinical  aspectsDr. E. Muralinath_ Blood indices_clinical  aspects
Dr. E. Muralinath_ Blood indices_clinical aspectsmuralinath2
 
Porella : features, morphology, anatomy, reproduction etc.
Porella : features, morphology, anatomy, reproduction etc.Porella : features, morphology, anatomy, reproduction etc.
Porella : features, morphology, anatomy, reproduction etc.Silpa
 
GBSN - Microbiology (Unit 1)
GBSN - Microbiology (Unit 1)GBSN - Microbiology (Unit 1)
GBSN - Microbiology (Unit 1)Areesha Ahmad
 
CURRENT SCENARIO OF POULTRY PRODUCTION IN INDIA
CURRENT SCENARIO OF POULTRY PRODUCTION IN INDIACURRENT SCENARIO OF POULTRY PRODUCTION IN INDIA
CURRENT SCENARIO OF POULTRY PRODUCTION IN INDIADr. TATHAGAT KHOBRAGADE
 
Chemistry 5th semester paper 1st Notes.pdf
Chemistry 5th semester paper 1st Notes.pdfChemistry 5th semester paper 1st Notes.pdf
Chemistry 5th semester paper 1st Notes.pdfSumit Kumar yadav
 
Grade 7 - Lesson 1 - Microscope and Its Functions
Grade 7 - Lesson 1 - Microscope and Its FunctionsGrade 7 - Lesson 1 - Microscope and Its Functions
Grade 7 - Lesson 1 - Microscope and Its FunctionsOrtegaSyrineMay
 
Bacterial Identification and Classifications
Bacterial Identification and ClassificationsBacterial Identification and Classifications
Bacterial Identification and ClassificationsAreesha Ahmad
 
Stages in the normal growth curve
Stages in the normal growth curveStages in the normal growth curve
Stages in the normal growth curveAreesha Ahmad
 
FAIRSpectra - Enabling the FAIRification of Analytical Science
FAIRSpectra - Enabling the FAIRification of Analytical ScienceFAIRSpectra - Enabling the FAIRification of Analytical Science
FAIRSpectra - Enabling the FAIRification of Analytical ScienceAlex Henderson
 
GBSN - Microbiology (Unit 2)
GBSN - Microbiology (Unit 2)GBSN - Microbiology (Unit 2)
GBSN - Microbiology (Unit 2)Areesha Ahmad
 
PSYCHOSOCIAL NEEDS. in nursing II sem pptx
PSYCHOSOCIAL NEEDS. in nursing II sem pptxPSYCHOSOCIAL NEEDS. in nursing II sem pptx
PSYCHOSOCIAL NEEDS. in nursing II sem pptxSuji236384
 
development of diagnostic enzyme assay to detect leuser virus
development of diagnostic enzyme assay to detect leuser virusdevelopment of diagnostic enzyme assay to detect leuser virus
development of diagnostic enzyme assay to detect leuser virusNazaninKarimi6
 
Human & Veterinary Respiratory Physilogy_DR.E.Muralinath_Associate Professor....
Human & Veterinary Respiratory Physilogy_DR.E.Muralinath_Associate Professor....Human & Veterinary Respiratory Physilogy_DR.E.Muralinath_Associate Professor....
Human & Veterinary Respiratory Physilogy_DR.E.Muralinath_Associate Professor....muralinath2
 
300003-World Science Day For Peace And Development.pptx
300003-World Science Day For Peace And Development.pptx300003-World Science Day For Peace And Development.pptx
300003-World Science Day For Peace And Development.pptxryanrooker
 
Introduction of DNA analysis in Forensic's .pptx
Introduction of DNA analysis in Forensic's .pptxIntroduction of DNA analysis in Forensic's .pptx
Introduction of DNA analysis in Forensic's .pptxrohankumarsinghrore1
 
Digital Dentistry.Digital Dentistryvv.pptx
Digital Dentistry.Digital Dentistryvv.pptxDigital Dentistry.Digital Dentistryvv.pptx
Digital Dentistry.Digital Dentistryvv.pptxMohamedFarag457087
 

Kürzlich hochgeladen (20)

Clean In Place(CIP).pptx .
Clean In Place(CIP).pptx                 .Clean In Place(CIP).pptx                 .
Clean In Place(CIP).pptx .
 
Module for Grade 9 for Asynchronous/Distance learning
Module for Grade 9 for Asynchronous/Distance learningModule for Grade 9 for Asynchronous/Distance learning
Module for Grade 9 for Asynchronous/Distance learning
 
Exploring Criminology and Criminal Behaviour.pdf
Exploring Criminology and Criminal Behaviour.pdfExploring Criminology and Criminal Behaviour.pdf
Exploring Criminology and Criminal Behaviour.pdf
 
Dr. E. Muralinath_ Blood indices_clinical aspects
Dr. E. Muralinath_ Blood indices_clinical  aspectsDr. E. Muralinath_ Blood indices_clinical  aspects
Dr. E. Muralinath_ Blood indices_clinical aspects
 
Porella : features, morphology, anatomy, reproduction etc.
Porella : features, morphology, anatomy, reproduction etc.Porella : features, morphology, anatomy, reproduction etc.
Porella : features, morphology, anatomy, reproduction etc.
 
GBSN - Microbiology (Unit 1)
GBSN - Microbiology (Unit 1)GBSN - Microbiology (Unit 1)
GBSN - Microbiology (Unit 1)
 
CURRENT SCENARIO OF POULTRY PRODUCTION IN INDIA
CURRENT SCENARIO OF POULTRY PRODUCTION IN INDIACURRENT SCENARIO OF POULTRY PRODUCTION IN INDIA
CURRENT SCENARIO OF POULTRY PRODUCTION IN INDIA
 
Chemistry 5th semester paper 1st Notes.pdf
Chemistry 5th semester paper 1st Notes.pdfChemistry 5th semester paper 1st Notes.pdf
Chemistry 5th semester paper 1st Notes.pdf
 
Grade 7 - Lesson 1 - Microscope and Its Functions
Grade 7 - Lesson 1 - Microscope and Its FunctionsGrade 7 - Lesson 1 - Microscope and Its Functions
Grade 7 - Lesson 1 - Microscope and Its Functions
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Bacterial Identification and Classifications
Bacterial Identification and ClassificationsBacterial Identification and Classifications
Bacterial Identification and Classifications
 
Stages in the normal growth curve
Stages in the normal growth curveStages in the normal growth curve
Stages in the normal growth curve
 
FAIRSpectra - Enabling the FAIRification of Analytical Science
FAIRSpectra - Enabling the FAIRification of Analytical ScienceFAIRSpectra - Enabling the FAIRification of Analytical Science
FAIRSpectra - Enabling the FAIRification of Analytical Science
 
GBSN - Microbiology (Unit 2)
GBSN - Microbiology (Unit 2)GBSN - Microbiology (Unit 2)
GBSN - Microbiology (Unit 2)
 
PSYCHOSOCIAL NEEDS. in nursing II sem pptx
PSYCHOSOCIAL NEEDS. in nursing II sem pptxPSYCHOSOCIAL NEEDS. in nursing II sem pptx
PSYCHOSOCIAL NEEDS. in nursing II sem pptx
 
development of diagnostic enzyme assay to detect leuser virus
development of diagnostic enzyme assay to detect leuser virusdevelopment of diagnostic enzyme assay to detect leuser virus
development of diagnostic enzyme assay to detect leuser virus
 
Human & Veterinary Respiratory Physilogy_DR.E.Muralinath_Associate Professor....
Human & Veterinary Respiratory Physilogy_DR.E.Muralinath_Associate Professor....Human & Veterinary Respiratory Physilogy_DR.E.Muralinath_Associate Professor....
Human & Veterinary Respiratory Physilogy_DR.E.Muralinath_Associate Professor....
 
300003-World Science Day For Peace And Development.pptx
300003-World Science Day For Peace And Development.pptx300003-World Science Day For Peace And Development.pptx
300003-World Science Day For Peace And Development.pptx
 
Introduction of DNA analysis in Forensic's .pptx
Introduction of DNA analysis in Forensic's .pptxIntroduction of DNA analysis in Forensic's .pptx
Introduction of DNA analysis in Forensic's .pptx
 
Digital Dentistry.Digital Dentistryvv.pptx
Digital Dentistry.Digital Dentistryvv.pptxDigital Dentistry.Digital Dentistryvv.pptx
Digital Dentistry.Digital Dentistryvv.pptx
 

Cpph exam a_2019_s1

  • 1. CPPH501 – PAPER A. (2019 S1) 1 YEAR: Student Number Surname & Initials 2019 SEMESTER: ASSESSMENT: 1 A SUBJECT NAME: Computer Programming 1 SUBJECT CODE: CPPH501 QUALIFICATION(S): D3IP13 /INDUSTRIAL PHYSICS PAPER DESCRIPTION: COMPUTER BASED DURATION: 3 HOURS PAPER: ONLY SPECIAL REQUIREMENTS  NONE  NON-PROGRAMMABLE POCKET CALCULATOR  SCIENTIFIC CALCULATOR  COMPUTER ANSWER SHEET  GRAPH PAPER  DRAWING INSTRUMENTS OTHER: COMPUTER INSTRUCTIONS TO CANDIDATES: ANSWER ALL QUESTIONS THIS TEST IS TO BE ANSWERED ON https://mytutor.tut.ac.za WHEN YOU ARE DONE. GIVE YOUR ANSWER SCRIPT BACK TO THE INVIGILATOR AND SUBMIT YOUR FILE. TOTAL NUMBER OF PAGES INCLUDING COVER PAGE: 12 TOTAL NUMBER OF ANNEXURES: 0 EXAMINER: W BHEBE FULL MARKS: 96 MODERATOR: A KHOZA TOTAL MARKS: 96 STUDENT TOTAL: ___ STUDENT %: ___ Tshwane Universit) of Technology
  • 2. CPPH501 – PAPER A. (2019 S1) 2 QUESTION 1 [10] STATEMENT TRUE FALSE Theory 1.1 The float and double data types in C++ store real numbers. 1.2 The condition in the selection structure specifies the decision you are making and is phrased so that it results in either a true or false answer only. 1.3 The repetition structure is used to repeatedly process one or more program instructions until some condition is met, at which time the structure ends. 1.4 A function header in a C++ program does not end with a semicolon. 1.5 You cannot include actual arguments when you call a void function. 1.6 A repetition structure can only include one instruction. 1.7 To use the predefined function sqrt(), the program must include the header file cmath. 1.8 The output of the statement: cout << pow(3.0, 2.0) + 5 << endl; is 14. 1.9 The following is an example of a valid function prototype: void calc(double, double, double &, double &); 1.10 The built-in srand function is an example of a value-returning function.
  • 3. CPPH501 – PAPER A. (2019 S1) 3 QUESTION 2 [10] In each of the following statements, choose the only correct answer. 2.1 The ____ structure makes a decision and then takes an appropriate action based on that decision a. selection b. case c. repetition d. iteration e. None of the above 2.2 ____ is an example of a syntax error. a. cout<<’Hello’; b. cin>>raiseRate; c. cout<<”New Pay :”<<newPay<<endl; d. average =number1 +number2/2; e. None of the above 2.3 The ____ statement tells the computer to leave the switch statement at that point. a. break b. continue c. stop d. case e. None of the above 2.4 If the default clause is not the last clause in the switch statement, you will need to Include a ____ statement at the end of the clause to stop the computer from processing the instructions in the next case clause. . a. continue b. break c. stop d. switch e. None of the above 2.5 A loop that processes its instructions indefinitely is referred to as a(n) ____ loop. a. infinite b. non sentinel c. accumulating d. incorrect e. None of the above
  • 4. CPPH501 – PAPER A. (2019 S1) 4 2.6 Every C++ program contains at least one function: ____. a. main() b. pow() c. return() d. rand() e. None of the above 2.7 In standard C++, the random number generator is a built-in function named ____. a. rand() b. random() c. rnd() d. rndm() e. None of the above 2.8 When a function definition appears below the main () function, you must enter a function ____ above the main() function. a. argument b. parameter c. prototype d. declaration e. None of the above 2.9 To pass a variable by reference in C++, you include a (n) ____ before the name of the corresponding formal parameter in the receiving function’s header. a. * b. @ c. # d. & e. None of the above 2.10 ____ is an example of a valid function call. a. void calc(double, double, double &, double &); b. calc(salary, raiseRate, raise, newSalary); c. void calc(double current, double rate, double &increase, double &pay) d. calc(salary, raiseRate, &raise, &newSalary); e. None of the above
  • 5. CPPH501 – PAPER A. (2019 S1) 5 QUESTION 2 (MULTIPLE CHOICE) 2.1 a b c d e 2.2 a b c d e 2.3 a b c d e 2.4 a b c d e 2.5 a b c d e 2.6 a b c d e 2.7 a b c d e 2.8 a b c d e 2.9 a b c d e 2.10 a b c d e
  • 6. CPPH501 – PAPER A. (2019 S1) 6 QUESTION 3 [21] 3.1 What is an escape character? Give an example. [2] 3.2 Propose an appropriate prototype of a function that will return the higher of any two numbers passed as argument to the function [4] 3.3. Write C++ statements for the following: [3] 𝑝𝑝 = �𝑎𝑎2 + 𝑏𝑏2
  • 7. CPPH501 – PAPER A. (2019 S1) 7 3.4. Write C++ statements for the following: [3] 𝑠𝑠𝑠𝑠𝑠𝑠 = 𝑎𝑎(𝑟𝑟𝑛𝑛 − 1) 𝑟𝑟 − 1 3.5 Explain in your own words, the term ‘modularity’ [3]
  • 8. CPPH501 – PAPER A. (2019 S1) 8 3.6 Study the following code and rewrite the program using a “for” loop [6] Write your answer in the space provided below int number = 1; do { cout << number << endl; number++; } while (number <= 10);
  • 9. CPPH501 – PAPER A. (2019 S1) 9 QUESTION 4 [16] Create a program that displays a series of the first 10 Fibonacci numbers (1, 1, 2, 3, 5, 8, 13, 21, 34, and 55). Notice that, beginning with the third number in the series, each Fibonacci number is the sum of the prior two numbers. In other words, 2 is the sum of 1 plus 1, 3 is the sum of 1 plus 2, 5 is the sum of 2 plus 3, and so on. Write two versions of the code: one using the for statement and the other using the while statement. Enter the C++ instructions into a source file named Question5.cpp. Add appropriate comments and any additional instructions required to execute your program. Note: the Fibonacci numbers should appear twice on the screen. Refer to figure 4.1 for sample output. Figure 4.1 QUESTION 5 [6] Write a C++ for loop that will produce the output in figure 5.1. Include appropriate comments and any additional instructions required to execute your program. Figure 5.1 I C:Usersraphirits.TUTD~sktopSickT~st2D~bugSickT~st2.~x~ i s playing t e the FIRST 10 i onacci umbers us ing [for s tatement] i s playing the the FIRST 10 Fibonacci umbers us ing [while s t a tement] any key to continue . . . _ Squat'e 4 16 36 64 100 any key Cube 8 64 216 512 1000 to continue V
  • 10. CPPH501 – PAPER A. (2019 S1) 10 Question 6 [23] Create a program for the sales manager at Computer Haven, a small business that offers motivational seminars to local companies. Table 6-1 shows the charge for attending a seminar. Notice that the charge per person depends on the number of people the company registers. For example, the cost for four registrants is R5 761.32; the cost for two registrants is R4 321.0. The program should allow the sales manager to enter the number of registrants for as many companies as needed. When the sales manager has finished entering the data, the program should calculate and display the total number of people registered, the total charge for those registrants, and the average charge per registrant. For example, if one company registers four people and another company registers two people, the total number of people registered is six, the total charge is R10 082.32, and the average charge per registrant is R1680.38. Number of people a company registers Charge per person (R) 1 – 3 2160.50 4 – 9 1440.33 10 or more 1296.30 Table 6.1 Include necessary statements to compile and run your program. See figure 6.1 for sample output.
  • 11. CPPH501 – PAPER A. (2019 S1) 11 Figure 5-1 QUESTION 7 [10] Write, compile and run a C++ program to input the following values into an array named velocity: 10.95, 16.32, 12.14, 8.33, 45.20, 36.45, 7.89, 12.35 and 11.54. After your data has been entered have your program display the values. first coApany (negative nuAber to stop the prograA): 4 registered by the next coApany (negative nuAber to stop the prograA): 2 registered by the next coApany (negative nuAber to stop the prograA): -5 otal nuAber of registrants: 6 otal charge for all registrants: R10082.32 uerage charge per registrant: R1680.39 registered by the next COApany (negative registered by the next COApany (negative registered by the next COApany (negative registered by the next COApany (negative registered by the next COApany (negative registered by the next COApany (negative registered by the next COApany (negative registered by the next COApany (negative registered by the next COApany (negative otal nuAber of registrants: 50 otal charge for all registrants: R?561?.39 verage charge per registrant: R1512.35 nm11ber to stop the pl"Ogl"aA): 8 nm11ber to stop the pl"Ogl"aA): 3 nm11ber to stop the pl"Ogl"aA): 1 nm11ber to stop the pl"Ogl"aA): 3 nm11ber to stop the pl"Ogl"aA): 4 nm11ber to stop the pl"Ogl"aA): ? nm11ber to stop the pl"Ogl"aA): 10 nm11ber to stop the pl"Ogl"aA): 9 nm11ber to stop the pl"Ogl"aA): -1 y
  • 12. CPPH501 – PAPER A. (2019 S1) 12 INSTRUCTIONS TO STUDENTS - All codes must be copied into a single file (MS word file, or any other format recommended by the lecturer) - The file name must match your student number - Student name and student number must be written at the top of the submitted file!! - All practical work must be submitted on myTutor - Make sure the lecturer or invigilator has collected your project before leaving the venue!