0% found this document useful (0 votes)
43 views4 pages

Computer 2 Exam

C++ programming exam

Uploaded by

joshua.nganga1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
43 views4 pages

Computer 2 Exam

C++ programming exam

Uploaded by

joshua.nganga1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 4
JOMO KENYATTA UNIVERSITY OF AGRICULTURE AND TECHNOLOGY University Examinations 2022/2023 YEAR 3 SEMESTER II EXAMINATION FOR THE DEGREE OF BSC ELECTRICAL AND ELECTRONICS ENGINEERING ICS 2276: COMPUTER PROGRAMMING II DATE: APRIL 2023 ‘TIME: 2 HOURS INSTRUCTIONS: ANSWER QUESTION ONE AND ANY OTHER TWO QUESTION ONE (30 MARKS) a) Preprocessor are commands that are executed before any other statement in your program. Describe any two such preprocessors used in C++ programming {4 Marks} b) Write down and explain the output of the following program {4 Marks} #include using namespace std; int main() { int x = 0; while (x < 10) { cout<< x < using namespace std; class vector public: double x; double y; double surface () Co aviuey SeRtY; if (s< 0) s = -8; return s; int main() { vector a; a.x=3; ay = 4; cout << The surface of a:<< a.surface() << endl; return 0; } b) Describe with examples the following terms as used in OOP i) Static memory allocation * ii) Dynamic memory allocatiort- iii) Constructors ~ iv) Destructors {8 Marks} c) Write a program that displays an invoice of several items. It should contain the item name, quantity, price, and total cost on each line for the quantity and item cost, It also contains methods to get and set item name, quantity, and price. Objects are created in main and invoices printed. 41 {7 Marks}

You might also like