Docsity

CGS 3460 Quiz 1 Solution, Quizzes of Computer Science

Toggle sidebar
bg1
CGS 3460 Quiz 1 Name:_____Answer Key______
February 10, 2006 UF ID: ____-----------_________
1. Which of the followings cannot be used as the identifier of a variable in a C program?
(20%)
choice type _score max-num case
typedef 3blocks long triple double
boil_point name constant char2int auto
private static intern extern $count
2. Describe what do the following UNIX commands do with one short sentence. (30%)
mkdir ______ Create a new directory ___________________________
cd ______ Change current directory to project _________________
tar –cvf sample.tar /HW1 _ pack all the files under directory HW1/ into a single
file called sample.tar, and the file is created under the current directory. ___ ls –
llist in long format (including details like permissions, owner,
size,etc.) rm cat.c _______ delete a file called cat.c under current directory
_______
3. Identify the 6 errors in the following c program. (30%)
#include <stdio.h>
#define PI 3.1415
/**************************************************
* This is the main function of problem 3, quiz 1 *
**************************************************/
main{} 1){
Float 2)
radius;
float circumference;
radius = 5: 3)
/* circumference = 2 times radius times PI /* PI is a constant */
4)*/
circumference =
radius * 2 * PI;
printf(‘Circumference of a circle with radius: %f is %f’ 5),
pf3

Partial preview of the text

Download CGS 3460 Quiz 1 Solution and more Quizzes Computer Science in PDF only on Docsity!

CGS 3460 Quiz 1 Name:_____Answer Key______ February 10, 2006 UF ID: ____-----------_________

  1. Which of the followings cannot be used as the identifier of a variable in a C program? (20%) choice type _score max-num case typedef 3blocks long triple double boil_point name constant char2int auto private static intern extern $count
  2. Describe what do the following UNIX commands do with one short sentence. (30%) mkdir ______ Create a new directory ___________________________ cd ______ Change current directory to project _________________ tar – cvf sample.tar /HW1 _ pack all the files under directory HW1/ into a single file called sample.tar, and the file is created under the current directory. ___ ls – l list in long format (including details like permissions, owner, size,etc.) rm cat.c _______ delete a file called cat.c under current directory
  3. Identify the 6 errors in the following c program. (30%) #include <stdio.h> #define PI 3. /************************************************** * This is the main function of problem 3, quiz 1 * **************************************************/ main{} 1){ Float 2) radius; float circumference; radius = 5: 3) /* circumference = 2 times radius times PI /* PI is a constant / 4)/ circumference = radius * 2 * PI; printf(‘Circumference of a circle with radius: %f is %f’ 5),

Radius6), circumference); } Answer: 1)Can’t use {} after main, should be main() 2)Not capital F, should be “float” 3)A statement can not end up with :, should be ; 4)A comment can’t be included inside another comment 5)Should use “” instead of ‘’ in the printf*/ 6)Radius should be radius

  1. Answer the following how-to and what-if questions: (20%) a) How to create an executable named success when given source code quiz1.c. _________ gcc quiz1.c – o success ___________________________________ b) How to create a tar file named bundle.tar that packs every file under the directory foo. _________ tar – cvf bundle.tar foo/___________________________________ c) Is it ok to break a comment enclosed by /* */ into multiple lines? _ Yes __ Is it ok to break a variable name such as length into two line such that len is on the first line and gth on the next? _ No _ Is it ok to break an assignment expression such as profit = revenue – cost between = and revenue into multiple lines? _ Yes _ Is it ok to break break a command such as printf into two lines such that print is on the first line and f on the next? _ No _ d) Describe concisely the steps you went through to complete problem 1 in the homework. Place one step in each of the line below (extra lines are provided for your convenience), and circle where does each step take place, remember, some steps may take place simultaneously both on your PC and grove server. Answer1: On PC: use telnet grove.ufl.edu to connect to grove machine. On grove: use pico to type in the C code and save it as HW1_1.c. On grove: gcc HW1_1.c – o HW1_ Answer2: On PC: use programmer’s file editor to type in the C code and save it as HW1_1.c with unix format. On PC: use Core FTP Lite to connect to grove.ufl.edu and transfer HW1_1.c to grove.ufl.edu.