Docsity

C++ past papers by muba, Summaries of Computer Science

Partial preview of the text

Download C++ past papers by muba and more Summaries Computer Science in PDF only on Docsity!

UKIHITAT! PEPA NYENGINE UNAWEzA KUNICHEF! 0739-263) 08 BY = MIbA MeENO de C++ PAST PAPER ~~ G CENTER ININ EASTERN AFRICA STAT]gTycAL TR* 7 NC BACHELOR og paTA SO# TH EH DSUO7103- PROGRAMMING WITH TEST 1 TIME: 1 hour DATE 28 NOV 2024 INSTRUCTIONS: Only use items acceptable in an examination. room Answers should be written on this ‘question paper Answer all questions. QUESTIONS. 1. Somebody said C-++ is a programming language, what does it mean. After finish your explanation mention at least three computer programs has c cout<< "umezaliwa muaka Ggani?\n"; Cin >>byear; - = Laie Be et ell age = x-byear; cout<<"your age is "< at lndude Leal using namespace std; int main(){ sdsstplaC lal) £1,¢,9,20,2,-6 4 NY int x, y, 2; ; / ate (C8) 4-6 ) abd! ugh Yak OPV AfxE, ergo, 231, return 0; . } Question 2 In the code snippet below, create two unique smart pointers. In the first space provided, include the header file for smart pointers. Use the second space to create the first pointer p1, pointing to an integer; store 30 in the allocated’ space. In the third space provided, move ownership of pointer p1 into p2 so that p2 points to a memory location pointed by p1 earlier. #include A Pe eserrar ee eee Af lacluch Lorbeamsb int main(){ *p, = 305 re dot P . return 0; } Question 3 Given the following code snippet, allocate memory to an array dynamically, then effectively _ deallocate memory, changing the pointer to null in the given spaces. The first space is for A gratisticA® TRAINING CENTER LOR OF paTA SCIENCE . RpaMMING WITH cH EASTERN AFRIC BACHE DSv107103- PROG pest ! TIME; 1 hour DATE 13 DEC 2023 oO a el —_—_—_—_—oOOo INSTRU TIONS: Only use items acceptable in an examination room Answers should be written on this question paper Answer all questions, QUESTIONS. 1. Every C++ program has 8 function called ¥. Gunenroil neues seats to A multi-line comment has re of symbols, which v 2 et: eke: Sees char, short, i i int, long, bool, unsigned char, unsigned short unsigned int ua unsigned long, long long, and unsigned long Jong, All this are called 4 e “ 44+ identifiers? Circle the valid ones. 4. Which of the following are valid 7S : () itstC++Prog Grave y Time 4 4 c). 3 feetInA Yard i One @& ne _ Which of the following variable declarations are c ,esinOneCentimeter orrect? Ifa variable Ww declaration is not correct, provide the correct variable declaration doubl Convesun =." 25 “ as . double conversion = 2.5; «rrr a b. char grade ="B+'; ......-+ OF eck Bam ei etd h. ven neg @eonigers H tl “ c. double 28.5 = num; __geoble ou, = ey Pores eras d. string message = "First C+Ht course’; 1 e. int age = 18 years; ......... acl ae ee ye a es ena f. float x, y, decimal;........4 BEE he wneee’ K. eee ee EASTERN AFRICA STATISTICAL TRAINING CENTER BACHELOR OF DATA SCIENCE DSU07103- PROGRAMMING WITH C++ TEST 1 TIME: | hour DATE $3" DEC 2023 INSTRUCTIONS: Only use items acceptable in an examination room Answers should be-written on this question paper Answer all questions. QUESTIONS. te | 1. Every C++ program has a function called ... FARRER ONTANE ...... Tatergratel? Reveloprmnt enviroomeht ( IDE). 2. A multi-line comment has the pair of symbols, which of 4. Which of the following are va ihn identifiers? Circle the valid ones. a). firstC++ Prog ©) rayél_Time 6) 3 feetlnA Yard d). number, 4 @® cpp_Assignment f). InchesInOneCentimeter 5. Which of the following variable declarations are correct? If a variable declaration is not correct, provide the correct variable declaration a. double conversion = DES sae correct parole b. char grade = 'Bt'; .....- Cormeen... c. double 28.5 = num, _ KSubte... Yum GO neces e, int age = 18 years; ...... COMI OT ciseeenre ess f. float x, y, decimal;....... CA reer coeconenrerhgh jane esses eaeee 6, The-data type bool has only two values: pals Ofer. FAN EASTERN AFRICA STATISTICAL TRAINING CE! BACHELOR OF DATA SCIENCE My DSU07103- PROGRAMMING WITH C++ TEST 24: TIME: 1 hour DATE 07 JAN 2025 o INSTRUCTIONS: i if y | Do not use any unauthorized in an examination room Use answer sheet provided to attempt all questions. QUESTIONS. a | rn } a Sy ‘ } Mt wee YS oN ‘ Rene. cay an Ue (esa ae Oh at saa oe ye jo [se A / 1. Knowing what you know so far please define what are keywords in C++ and give three examples. ; ‘| ced p/ 2. How is a variable declared in C++? Provide examples. _43, Can if conditions use logical operators like && and \? Give an example. » = 2 \ V4, What is the difference between a while.and a do-while loop? provide iN - $ ’ example. a: a / 5. Identify the error in these codes: _ ia intx = "10"; cout << x; 6 yo yh ers aa * 6. What is an infinite loop? Write an example of at infinite loop using a while loop. WA "What is the output of the following code? string str = "Hello"; i cout << str[1]; \ 1% " aq i . Ruel ag 8. What is the output of the following code? gt aI pt Aete » Tt 5 for (int i = 0; i <= 20; j+=2) { 6 if. (| %4==0) { a F Vs z continue: oe a | \ Za ) cout< 1 2 3 int sum(int k) { 4 if (k > @) return k + sum( 5 else return @; 6 } 7 8 int main() { 9 std::cout << sum(10); 10 return Q; il} Output: 43 22 2 4, S 6,% Question 4: Determine the output of the followi 1 #include 2 : = 3 int main() { Be an 3 etca th eee eS 4 std::string cars{4] = > ¢"yolwo" , “BMW”, “Ford", "Mazda"}; 5 std::cout << cars[3]; 6 return Q; 7 } Output: Mazda wing ko 1 code snippet yt at Question 5: Determine the output of the fo #include int main() { int x = 5; X %= 3; std::cout << Xx; return @7. °° On Au BP WY Be Output: 2 TATISTICAL T EASTERN AFRICAS RAINING CENTER’ HIGHER ek IN DATA SCIENCE 03: Programming with C-+ DSU ee TEST? Time: 1 hour = Date: 315 January 2024 Question“I: Given the code snippet below, determine the output - #include - return. 0; PLB cakaabsicalaniitied a Lon ited ard alee 2 Ei L antiput if 4-14 UD)