12.07.2015 Views

Answer - Index of - This is CS50.

Answer - Index of - This is CS50.

Answer - Index of - This is CS50.

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Th<strong>is</strong></strong> <strong>is</strong> <strong>CS50.</strong> Harvard College Fall 2010 Quiz 0 <strong>Answer</strong> Key <strong>Answer</strong>s other than the below may be possible. Multiple Choice. 0. a 1. a 2. b 3. c 4. b 5. d True or False. 6. T or F 7. T 8. F 9. T 10. T or F Itching for Week 0? 11. 00011001+ 00011001 0011001012. #include intmain(void){int n = 10;while (n > 0){printf("%d", n);n--;}printf("Blast<strong>of</strong>f!");}0 < 8


<strong>Th<strong>is</strong></strong> <strong>is</strong> <strong>CS50.</strong> Harvard College Fall 2010 Role Reversal. 13. <strong>Th<strong>is</strong></strong> program always prints zero, no matter its input. Removing the semicolon on the same line as if fixes the problem. 14. <strong>Th<strong>is</strong></strong> program always prints one, no matter its input. Changing the = to == in the program’s condition fixes the problem. Big OMG. 15. Algorithm O Ω sorting an array with Merge Sort n log n n log n sorting an array with Selection Sort n 2 n 2inserting into a sorted linked l<strong>is</strong>t n 1 searching a sorted array with Binary Search log n 1 searching a sorted linked l<strong>is</strong>t with Linear Search n 1 Bit W<strong>is</strong>e. 16. type charchar *doubledouble *intint *unsigned intlong longbits 8 32 64 32 32 32 32 64 1 < 8


DOCUMENTACIÓN QUE DEBE APORTAR- Original y copia del documento identificativo del trabajador/a ante la Seguridad Social. En el supuesto de variaciones de datoscontenidos en el anterior documento, se deberán presentar el original del documento que acredite tal variación: DocumentoNacional de Identidad, Tarjeta de Extranjero o Pasaporte, dependiendo del caso.- Original y copia del perm<strong>is</strong>o de trabajo o certificación de la excepción al citado perm<strong>is</strong>o, en las altas de trabajadores denacionalidad extranjera que prec<strong>is</strong>en tal perm<strong>is</strong>o de trabajo.- Original y copia de cualquier documento o medio de prueba determinante de la procedencia del alta, baja o variación dedatos solicitados, entre los cuales podrán encontrarse alguno o algunos de los siguientes documentos:* Si se trata de un trabajador/a autónomo d<strong>is</strong>tinto a los colaboradores familiares de titulares de explotaciones o religiosos de laIglesia Católica, comunicación de inicio de actividad en la Declaración Censal de la Agencia Estatal de la Admin<strong>is</strong>traciónTributaria o justificante de haber abonado cualquier otro impuesto por la actividad desempeñada o certificación de no abonardichos impuestos por estar exento de los m<strong>is</strong>mos.* Si se trata de un trabajador autónomo colaborador familiar de titulares de explotaciones, justificante de la relación deparentesco entre el solicitante y el titular de la explotación (Libro de familia).* Si se trata de un trabajador/a familiar del socio de una Sociedad Mercantil Capital<strong>is</strong>ta, justificante de la relación deparentesco entre el solicitante y el titular de la explotación (Libro de familia) y de la convivencia entre ambos.*Si se trata de un trabajador/a autónomo minusválido, documento que acredite el grado de minusvalía y, en su caso,resolución de laAdmin<strong>is</strong>tración competente por la que se aprueba el proyecto de autoempleo.* Licencias, perm<strong>is</strong>os o autorizaciones admin<strong>is</strong>trativas, que sean necesarios para la actividad de que se trate.* Documentación que acredite que el solicitante ostenta la titularidad de cualquier empresa individual o familiar o de unestablecimiento abierto al público como propietario/a, arrendatario/a, usufructuario/a u otro concepto análogo o documentoacreditativo del cese en dicha titularidad.- Si se trata de un trabajador/a autónomo socio de una sociedad inscrita, o no, en la Seguridad Social, original y copia deldocumento de constitución de la sociedad, debidamente inscrita en el Reg<strong>is</strong>tro que, en cada caso, corresponda; en elsupuesto de componentes de Comunidades de Bienes o Sociedades Civiles, el contrato suscrito por los comuneros osocios.


<strong>Th<strong>is</strong></strong> <strong>is</strong> <strong>CS50.</strong> Harvard College Fall 2010 Programmer Error. 25. Because the parameter, c, to capitalize <strong>is</strong> passed by value, the function receives a copy <strong>of</strong> whatever character <strong>is</strong> passed in. That character <strong>is</strong> indeed capitalized within the scope <strong>of</strong> that function, but as soon as the function returns, the capitalized character <strong>is</strong> lost (because it’s popped <strong>of</strong>f the stack). <strong>Th<strong>is</strong></strong> problem can be fixed by having capitalize return the capitalized character, as in the below. charcapitalize(char c){if (<strong>is</strong>lower(c))return toupper(c);elsereturn c;}With capitalize so defined, the caller must now retain th<strong>is</strong> return value, as in the below. c = capitalize(c);Alternatively, capitalize can be declared as expecting a pointer, as in the below. voidcapitalize(char *c){if (<strong>is</strong>lower(*c))*c = toupper(*c);}With capitalize so defined, the caller must now call the function as follows. capitalize(&c);Bottle(s). 26. Because the s in line 15 inside <strong>of</strong> a branch, its scope <strong>is</strong> limited to lines 14 through 16; although s <strong>is</strong> assigned a value, that value goes unused. Similarly does the s in line 19 only ex<strong>is</strong>t between lines 18 and 20; its value, too, goes unused. And so in line 21, which outside <strong>of</strong> those scopes, s appears to be undeclared. 27. <strong>Th<strong>is</strong></strong> program <strong>is</strong> intended to print bottle if the user inputs 1, else bottles if the user inputs 0 or an integer greater than 1. 3 < 8


<strong>Th<strong>is</strong></strong> <strong>is</strong> <strong>CS50.</strong> Harvard College Fall 2010 Pointer Fun without Binky. 28. GetString returns the address in memory <strong>of</strong> a string inputted by a user. And so if GetString <strong>is</strong> called twice, it returns two different (i.e., unequal) addresses, one for each string, even if both happen to compr<strong>is</strong>e the same characters. 29. statement what would be printed printf("%d", i); 1printf("%d", j); 3printf("%d", *p); 3printf("%d", k); 730. intstrlen(char *s){int n = 0;if (s == NULL)return n;for (int i = 0; s[i] != '\0'; i++)n++;return n;}4 < 8


<strong>Th<strong>is</strong></strong> <strong>is</strong> <strong>CS50.</strong> Harvard College Fall 2010 (Proto)typical Alex. 31. prototype bool<strong>is</strong>alnum(char c) chartolower(char c) bool<strong>is</strong>upper(char c) bool<strong>is</strong>digit(char c) function typefunction(parameter){if (<strong>is</strong>alpha(c) || <strong>is</strong>digit(c))return true;elsereturn false;}typefunction(parameter){if ('A'


<strong>Th<strong>is</strong></strong> <strong>is</strong> <strong>CS50.</strong> Harvard College Fall 2010 Ah, memories. 32. text ⎬⎬ program itself initialized data ⎬⎬ global variables declared with values uninitialized data ⎬⎬ global variables declared without values heap ↓ ⎬⎬ memory that’s been dynamically allocated with malloc ↑ stack environment variables ⎬⎬ ⎬⎬ functions’ parameters and local variables special variables like the user’s username 6 < 8


<strong>Th<strong>is</strong></strong> <strong>is</strong> <strong>CS50.</strong> Harvard College Fall 2010 Argh. 33. statement printf("%s", argv[0]);what would be printed ./a.outprintf("%c", argv[0][1]); /printf("%c", argv[1][0]);fprintf("%s", &argv[1][1]);ooprintf("%d", strlen(argv[0])); 7printf("%d", strlen(&argv[0][2])); 5printf("%d", argc); 4From Floor to Ceiling. 34. intfloor(float x){return (int) x;}35. intceil(float x){if (x – (int) x > 0.0)return (int) (x + 1.0);elsereturn (int) x;}PC LOAD LETTER. 36. doublesteal(double interest){return interest - round(interest * 100) / 100;}7 < 8

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!