Computer Science > QUESTIONS & ANSWERS > Answers-FinalReview(1)[cse]Review Questions CSE 100[100% correct (All)
Review Questions CSE 100 1. Write the code snippet for taking a user input (string) and storing each character into an array called letters. string input; cout << "enter the string"; cin >> input... ; int length = input.length(); cout << "Length: " << length << endl; int SIZE = length; char a [100]; for (int i =0; i < length; i++) a[i] = input.at(i); for (int i=0; i < length; i++) cout << a[i] << " " ; 2. What is cout<<fixed used for? It writes floating point values in fixed-point notation. 3. How can an integer be converted to a double? static_cast<double> (number); 4. Which formatting function helps control the width of the output. setw() 5. Write a function called bool isPrime(int number) which finds out whether a given number is prime or not and returns true accordingly. bool isPrime(int number) { bool flag = false; for (int i = 2; i<number; i++) { if(number % i== 0) { return flag; } } flag = true; return flag; } 6. Give an example where you would use pass by value and pass by reference. When the value of the argument is not intended to be changed in the function we use pass by value, for example as in given in isPrime() function. When the value of the passed argument is desired to be changed both in the called function and in the calling function we use pass by reference. For example, void increment(int &number) { number++; } In the above function the value of number is incremented both in the function increment and in the function calling increment. Use the following code to answer the next three questions // Read the code carefully. #include <iostream> using namespace std; int h( int, int & ); int main() { int c = 1, d = 3; cout << h( c, d ) << endl; // Line 1 cout << h( d, c ) << endl; // Line 2 cout << c << endl; // Line 3 } int h( int a, int & b ) { b = b - 1; if (b > 0) cout << b << endl; // Line 4 if (a > 1) a--; return a; } 7. What value is displayed the first time Line 4 is executed? 2 8. What value is displayed when the cout stream in Line 2 is executed? 1 9. What value is displayed when Line 3 is executed? 0 10. Given the following: int a[5][7],b[5][7]; Which of the following statements are correct: a =b ; //Incorrect a[1][2]=b[3][4]; // Correct a[0][-1] = -1; // Incorrect 11. Write the specification file for the UML class given below: Student -Name :string -Id:string -department:string +Student(name,id) +getName():string +getId():string +setDept(string):void class Student { private: string Name; string Id; string department; public: Student(string,string); string getName(); string getId(); void setDept(string); } 12. Instantiate an object of the class above and call the setDept() method with the necessary arguments. Student student1(“Smith”, “123456”); student1.setDept(“CSE”); [Show More]
Last updated: 2 years ago
Preview 1 out of 6 pages
Buy this document to get the full access instantly
Instant Download Access after purchase
Buy NowInstant download
We Accept:
Can't find what you want? Try our AI powered Search
Connected school, study & course
About the document
Uploaded On
Apr 20, 2021
Number of pages
6
Written in
This document has been written for:
Uploaded
Apr 20, 2021
Downloads
0
Views
47
In Scholarfriends, a student can earn by offering help to other student. Students can help other students with materials by upploading their notes and earn money.
We're available through e-mail, Twitter, Facebook, and live chat.
FAQ
Questions? Leave a message!
Copyright © Scholarfriends · High quality services·