15AG_Test1_Answers-1

15AG_Test1_Answers-1 - CIS 15AG 1 Test 1 Answers Chapters...

Info icon This preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
CIS 15AG Test 1 Answers: Chapters 1-5 Computer Science is no more about computers than astronomy is about telescopes. - Edsgar W. Dijkstra Chapters: 1 - 5 ______________________________________________________________________ 1. (10 Points ) You are given two files both containing machine language. The first file, let's call it FILE_1 has 161KB, and the second one, FILE_2, has 3 KB. Both files were created when working on a C program. (A) (2 Points ) Which one represents the object module? FILE_2 (B) (8 Points ) Why? Because File_2 has 3KB < 161KB, the size of FILE_1. An executable, i.e. FILE_1, contains the object module, FILE_2, and other object modules from the system's library. _______________________________________________________________________ _ 2. (10 Points ) Define a float variable named amount , an int variable num , and two char variables letter1 and letter1 , then code one statement that will read the following data stream entered by the user from the keyboard into the variables described above. A B 23.18 45 // Local Declarations float amount; int num; char letter1, letter2; // Statements scanf( "%c %c%f%d", &letter1, &letter2, &amount, &num ); 1
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
CIS 15AG Test 1 Answers: Chapters 1-5 one space must be used, otherwise letter2 will contain space and B would be invalid input for amount! _______________________________________________________________________ _ 3. (10 Points ) Predict the output. int num = 725; int a = 2; int b = 3; int c; c = a + 5 * b; // Write the output below printf( "%d\n", c ); // 2 + 5 * 3 = 2 + 15 = 17 num %= 100; printf( "%d\n", num ); // 725 % 100 is 25 – the remainder num = 725; c = num / 100 * 100; // 725 / 100 * 100 = 7 * 100 = printf( "%d\n", c ); // 700 c = a + b++; // 2 + 3 is 5, then b changes to 4 printf( "%d %d\n", b, c ); // 4 5 b = 3; // 3 c = a + ++b; // first b changes to 4, then 2 + 4 printf( "%d %d\n", b, c ); // 4 6 a = 5; b = 7; c = !(a < b); // Write the output below printf( "%d\n", c ); // 0 (false) c = a > 0 && a < b; printf( "%d\n", c ); // 1 (true and true is true) c = b <= 0 || b >= a; printf( "%d\n", c ); // 1 (false or true is true) c = a < b || a > 0 && b != 9; // true or (anything) is true printf( "%d\n", c ); // 1 // (true and true) is true 2
Image of page 2
CIS 15AG Test 1 Answers: Chapters 1-5 c = a < b && a > 0 || b != 9; // true or anything is true printf( "%d %d\n", b, c ); // 1 3
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
CIS 15AG Test 1 Answers: Chapters 1-5 _______________________________________________________________________ _ 4. (10 Points ) (A). Assume a, b, c, x1, and x2 have already been defined as double variables, and that a, b, and c have values ( a not zero). Write statements to calculate x1 and x2 using the formulae at page 301, project 64. double temp; temp = sqrt(b*b – 4*a*c); x1 = (-b + temp) / (2*a); x2 = (-b - temp) / (2*a); (B). Assume myRand is a variable of type int . Write a statement that would assign to this variable a random number within the range -55 to 99 . myRand = rand() % 155 – 55; (C). Assume aChar is a variable of type char . Prompt the user to enter a character, then use the appropriate functions to check if it is a digit or an uppercase letter, and if it is, print it, otherwise print “Error”. printf(" Enter a character: "); scanf ("%c ", &aChar ); if( isDigit(aChar) || isUpper(aChar) ) printf("%c\n", aChar); else printf("Error\n"); 4
Image of page 4
CIS 15AG Test 1 Answers: Chapters 1-5 _______________________________________________________________________ 5.
Image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern