Many job seekers walk into an interview ill-prepared, expecting the employer to ask all the questions.
Wrong move, says Ford R. Myers, author of "Get The Job You Want, Even When No One's Hiring," (John Wiley & Sons, 2009).
"Asking smart questions will help the job seeker sound articulate, well-prepared and genuinely interested in working for the organization," says Myers.
Myers recommends asking the following questions to find out as much as possible about the job and leave a good impression.



1. Can you give me more detail about the position's responsibilities?

1. Can you give me more detail about the position's responsibilities?

2. Where do you see this position going in the next few years?

2. Where do you see this position going in the next few years?
en321viaFlickr

3. How can I most quickly become a strong contributor within the organization?

3. How can I most quickly become a strong contributor within the organization?
usfbpsviaFlickr

4. What are the most challenging aspects of the job for which I am being considered?

4. What are the most challenging aspects of the job for which I am being considered?

5. How will my performance be evaluated, and at what frequency?

5. How will my performance be evaluated, and at what frequency?

6. What particular aspects about my background and experience interest you?

6. What particular aspects about my background and experience interest you?
scoviaFlickr

7. What makes you think I will be successful in this job? What causes you concern about my candidacy?

7. What makes you think I will be successful in this job? What causes you concern about my candidacy?

8. Now that we've had a chance to talk, how does my background measure up to the requirements of the job? To the other candidates?

8. Now that we've had a chance to talk, how does my background measure up to the requirements of the job?  To the other candidates?
jerineviaFlickr

9. Where are you in the hiring process? What's our next step?

9. Where are you in the hiring process? What's our next step?
usfbpsviaFlickr

10. If I don't hear from you within (time period), would it be okay to call you?

10. If I don't hear from you within (time period), would it be okay to call you?

Wednesday, June 20, 2012

trigraphs in c


trigraph" -- C Language" "


trigraph is a set of three characters that represents one character in the C character set. The set of trigraph sequences was defined in the ANSI Standard to allow users to use the full range of C characters, even if their keyboards do not implement the full C character set. Trigraph sequences are also useful with input devices that reserve one or more members of the C character set for internal use; e.g., the Hazeltine family of terminals, which reserves the tilde `~' as its escape character.
Each trigraph sequence is introduced by two question marks. The third character in the sequence indicates which character is being represented. The following table gives the set of trigraph sequences:
      _ T_ r_ i_ g_ r_ a_ p_ h  _ C_ h_ a_ r_ a_ c_ t_ e_ r
      _ S_ e_ q_ u_ e_ n_ c_ e _ R_ e_ p_ r_ e_ s_ e_ n_ t_ e_ d

         ??=        #
         ??(        [
         ??/        \
         ??)        ]
         ??'        ^
       ??<       {
         ??!        |
       ??>       }
         ??-        ~
The characters represented are the ones used in the C character set but not included in the ISO 646 character set. ISO 646 describes an invariant sub-set of the ASCII character set.
Trigraph sequences are interpreted even if they occur within a string literal or a character constant. Thus, strings that uses a literal ``??'' will not work the same as under a non-ANSI implementation of C. For example, the function call
     printf("Feel lucky, punk??!\n");
would print:
     Feel lucky, punk|
To print a pair of questions marks, use the escape sequence `\??'. For example:
     printf("Feel lucky, punk\??!\n");


The BASIC programming language was developed in 1965 by John G. Kemeny and Thomas E. Kurtz as a language for introductory courses in computer science. In 1988 they extended the language to make it modular and portable.




1. Introduction
True BASIC, C, Fortran, and Pascal are examples of procedural languages. Procedural languages change the state or memory of the machine by a sequence of statements. True BASIC is similar to F (a subset of Fortran 90) and has excellent graphics capabilities which are hardware independent. True BASIC programs can run without change on computers running the Macintosh, Unix, and Windows operating systems. We will consider version 3.0 (2.7 on the Macintosh) of True BASIC. Version 5 includes the ability to build objects such as buttons, scroll bars, menus, and dialog boxes. However, because we wish to emphasize the similarity between True BASIC and other procedural languages such as C, F, and Java, we do not consider these features.
There is no perfect programming language (or operating system) and users should be flexible and choose the appropriate language to accomplish their goals. Former students who were well grounded in True BASIC have had no trouble learning C, F, and Java quickly.
This tutorial is based on the text, Introduction to Computer Simulation Methods, by Harvey Gould and Jan Tobochnik. The features of True BASIC which are common to other procedural languages are emphasized.
To illustrate the nature of True BASIC, we first give a program that multiplies two numbers and prints the result:
PROGRAM product
! taken from Chapter 2 of Gould & Tobochnik
LET m = 2                         ! mass in kilograms
LET a = 4                         ! acceleration in mks units
LET force = m*a                   ! force in Newtons
PRINT force
END
The features of True BASIC included in the above program include: The first statement is an optional PROGRAM header. The inclusion of a program header is good programming style.
 Comment statements begin with ! and can be included anywhere in the program.
 PROGRAM, LET, PRINT, and END are keywords (words that are part of the language and cannot be redefined) and are given in upper case. The case is insignificant (unlike C, F, and Java). The DO FORMATcommand converts keywords to upper case.
 The LET statement causes the expression to the right of the = sign to be evaluated and then causes the result to be assigned to the left of the = sign. (The LET statement reminds us that the meaning of the = symbol is not the same as equals.) It is not necessary to type LET, because the DO FORMAT command automatically inserts LET where appropriate. The LET statement can be omitted if the OPTION NOLET statement is included.
 True BASIC does not distinguish between integer numerical variables and floating point numerical variables and recognizes only two types of data: numbers and strings (characters). The first character of a variable must be a letter and the last must not be an underscore.
 The PRINT statement displays output on the screen.
 The last statement of the program must be END.
We next introduce syntax that allows us to enter the desired values of m and a from the keyboard.
PROGRAM product2
INPUT m
INPUT prompt "acceleration a (mks units) = ": a
LET force = m*a                       ! force in Newton's
PRINT "force (in Newtons) ="; force
END
Note the difference between the INPUT and INPUT prompt statements and the simple modification of the PRINT statement. What happens if you replace the semicolon after the expression in the PRINT statement by a comma? Modify the program so that it adds, subtracts, and divides two numbers.2. Loop structuresTrue BASIC uses a FOR or a DO construct to execute the same statements more than once. An example of a FOR loop follows:
PROGRAM series
! add the first 100 terms of a simple series
! True BASIC automatically initializes variables to zero,
! but other languages might not.
LET sum = 0
FOR n = 1 to 100
    LET sum = sum + 1/(n*n)
    PRINT n,sum
NEXT n
END
 The use of the FOR loop structure allows a set of statements to be executed a predetermined number of times. The index or control variable (n in Program series) monitors the number of times the loop has been executed. The FOR statement specifies the first and last value of the index and the amount that the index is incremented each time the NEXT statement is reached. Unless otherwise specified, the index is increased by unity until the index is greater than its last value in which case the program goes to the statement after the NEXT statement. In Program series, the index n assumes the values 1 through 100. True BASIC treats n as an integer variable. The block of statements inside the loop is indented for clarity. Use the DO FORMAT command to indent loops automatically.
 The order of evaluation follows the mathematical conventions shared by all computer languages. Exponentiations are performed first, followed by multiplications and divisions from left to right. Parentheses should be used whenever the result might be ambiguous to the reader. The parentheses in the statement, LET sum = sum + 1/(n*n), are included for clarity.
 All unassigned variables are automatically initialized to zero. Because C, F, and Java do not, it is recommended that variables such as sum in Program series be initialized explicitly.
In many cases the number of repetitions is not known in advance. An example of a DO loop follows:
PROGRAM series_do
! illustrate use of DO LOOP structure
LET sum = 0
LET n = 0
LET relative_change = 1           ! choose large value
DO while relative_change > 0.0001
   LET n = n + 1
   LET newterm = 1/(n*n)
   LET sum = sum + newterm
   LET relative_change = newterm/sum
   PRINT n,relative_change,sum
LOOP
END
Note the use of the DO while loop structure to repeat the sum until the specified condition is no longer satisfied. An example of the DO until loop structure is illustrated in Program example_f.3. Conditional statementsThe IF statement lets a program branch to different statements depending on the outcome of previous computations. An example of the use of the IF statement follows:
PROGRAM decision1
LET x = 0
DO while x < 20
   LET x = x + 1
   IF x <= 10 then
      LET f = 1/x
   ELSE
      LET f = 1/(x*x)
   END IF
   PRINT x,f
LOOP
END
The IF construct is a compound statement which begins with IF ... then and ends with END IF. The sequence of statements (a block) inside the IF construct is indented for clarity (done automatically by the DO FORMAT command). An example of the IF statement with two or more branches is given by:
PROGRAM decision2
LET x = 0
DO while x <= 30
   IF x = 0 then
      LET f = 0
   ELSEIF x <= 10 then
      LET f = 1/x
   ELSEIF x <= 20 then
      LET f = 1/(x*x)
   ELSE
      LET f = 1/(x*x*x)
   END IF
   PRINT x,f
   LET x = x + 1
LOOP
END
Any number of ELSEIF statements may be used in an IF structure, and IF statements may be nested.The decisions of an IF structure are based on (logical or Boolean) expressions which are either true or false. A logical expression is formed by comparing two numerical or two string expressions by a relational operator. These operators are given in Table 1.

Table 1. Summary of relational operators.
relationoperator
equal=
less than<
less than or equal<=
greater than>
greater than or equal>=
not equal<>
If all the choices in the decision structure are based on the value of a single expression, it is sometimes convenient to use a SELECT CASE structure.
Although True BASIC explicitly recognizes only two kinds of variables, numeric and string, it implicitly distinguishes between floating point (real) and integer numeric variables. For example, the variable x in Program decision2 is treated as an integer variable and hence stored with infinite precision; the variable f is treated as a real variable and stored to 14 to 16 decimal places depending on the computer. Arithmetic with numbers represented by integers is exact, but arithmetic operations which involve real numbers is not. For this reason, decision statements should involve comparisons of integer variables rather than floating point variables.
C and Fortran 90 support the WHILE statement, but F does not. A program equivalent to Program decision2 is given in the following:
PROGRAM decision3
LET x = 0
DO
   LET x = x + 1
   IF x <= 10 then
      LET f = 1/x
   ELSE
      LET f = 1/(x*x)
   END IF
   PRINT x,f
   IF x = 20 then
      EXIT DO                  ! note syntax
   END IF
LOOP
END
4. Subprograms and local and shared variables
dummy variables functions random number sequences
It is convenient to divide a program into smaller units consisting of a main program and subprograms consisting of subroutines and functions. Subprograms are called from the main program or other subprograms. As an example, the following program adds and multiplies two numbers which are inputed from the keyboard.
PROGRAM tasks            ! illustrate use of subroutines
! note how variables are passed
CALL initial(x,y)                 ! initialize variables
CALL add(x,y,sum)                 ! add two variables
CALL multiply(x,y,product)
PRINT "sum ="; sum, "product ="; product
END                               ! end of main program

SUB initial(x,y)
    INPUT x
    INPUT y
END SUB

SUB add(x,y,sum)
    LET sum = x + y
END SUB

SUB multiply(x,y,product)
    LET product = x*y
END SUB
 Program tasks is an example of a modular program, a program which is divided into separate tasks each of which can be written and tested separately. A complete program contains a main program consisting of a series of calls to subprograms. Subroutines are invoked by the CALL statement. Subroutines and functions are called from the main program or other subprograms. A subroutine is defined by a SUB statement; the end of a subroutine is denoted by END SUB. We use only external subroutines and functions. External program units are defined in any order after the END statement of the main program.
 A subroutine is a separate program unit with its own local variables, that is, the variables in the main program and in each external subroutine and function are available only to the program subunit. A variable name represents a memory location in the computer. If the same variable name is used in two program units, the name represents two different memory locations.
The most common method for subroutines to pass information to the main program and to other subroutines is via arguments in the subroutine calls. In Program tasks the variables x, y, sum, and product are passed in this way. (It is a little misleading to say that variable names are passed to a subroutine. More precisely, the variable names are not passed, but rather the memory location in the computer is passed. The variable name is simply a label that identifies the memory location.)
In Program no_pass the variable name x is used in the main program and in SUB add_one, but is not passed. Convince yourself that the result printed for x in the main program is 10. What is the value of x in SUB add_one?
PROGRAM no_pass
LET x = 10             ! local variable name x defined in main program
CALL add_one
PRINT x
END

SUB add_one
    ! variable name x not passed
    LET x = x + 1      ! local variable name defined in subroutine
END SUB
What are the values of x and y if SUB add_one in Program pass is written in the following form?
PROGRAM pass
LET x = 10
LET y = 3
CALL add_one(x)
CALL add_one(y)
PRINT x,y
END

SUB add_one(s)              ! example of the use of dummy arguments
    LET s = s + 1
END SUB
 The variable name in the subroutine declaration need not match the name used in calling the subroutine. We call the declaration variable name a "dummy variable," because it may not actually be used in the program execution. It is only necessary that the number of variables in the declaration equal the number in the calling of a subroutine. Another way of passing information in True BASIC is discussed later.
An example of the use of a function is given in the following:
PROGRAM example_f
! example of use of external function
DECLARE DEF f
LET delta = 0.01                  ! incremental increase
LET sigma2 = 1                    ! variance 
LET x = 0                         ! initialize variables even though unnecessary
DO
   PRINT x,f(x,sigma2)
   LET x = x + delta
LOOP until key input
END

DEF f(x,sigma2)
    ! define Gaussian function with zero mean and variance sigma2
    LET f = (2*pi*sigma2)^(-0.5)*exp(-x*x/(2*sigma2))
END DEF
Note that functions do not change the values of arguments to them. Definitions are not limited to a single line. One way to stop a program is to have the user hit any key as shown by the use of the key input statement in Program example_f.
 The exponentiation operator is ^.
 The quantity pi (the area of a circle with unit radius) is predefined. Its use is illustrated in Program example_f. (Strictly speaking, pi is a function which has no arguments and whose value is pi.)
True BASIC has many intrinsic (built-in) functions. Some of the more frequently used mathematical functions are given in Table 2.
Table 2. Useful mathematical functions.
notationfunction
abs(x)absolute value
sqr(x)square root
exp(x)exponential function
log(x)natural logarithm
log10(x)logarithm base 10
sin(x)sine function
cos(x)cosine function
tan(x)tangent function
int(x)integer part
mod(x,y)remainder when x is divided by y
max(x,y)larger of x and y
min(x,y)smaller of x and y
remainder(x,y)mod(x,y) - y
If you are uncertain how a particular function works, write a little program to test it. For example, what is the value of mod(10,3)? What about mod(-10,3)? What is the difference between the MOD and the REMAINDER functions?
True BASIC includes several useful built-in functions besides pi. One of the most useful ones is rnd which produces a random number that is uniformly distributed between zero and one. The same sequence of random numbers appears each time the program is run unless the function RANDOMIZE is called before the rnd function is used. An example of a program which generates random sequences of integers between 1 and N is given below.
PROGRAM random
RANDOMIZE
LET N = 100
FOR i = 1 to N
    LET integer = int(N*rnd) + 1
    PRINT integer;
NEXT i
END
Because the effect of the int function is to round the output of rnd down to its nearest integer, it is necessary to add 1.Although it is a good idea to write your own random number generator using an algorithm that you have tested on the particular problem of interest, it is convenient to use the rnd function when you are debugging a program or if accuracy is not important.
5. ArraysAn array variable is a data structure consisting of an ordered set of elements of the same data type. One advantage of arrays is that they allow for the logical grouping of data of the same type, for example the x and y coordinates of a particle. The dimension of an array and the passing of arrays to a subroutine is illustrated in Program vector:
PROGRAM vector                    ! illustrate use of arrays
DIM a(3),b(3)                     ! arrays defined in DIM statement
CALL initial(a(),b())
CALL dot(a(),b())
CALL cross(a(),b())
END

SUB initial(a(),b())
    LET a(1) = 2
    LET a(2) = -3
    LET a(3) = -4
    LET b(1) = 6
    LET b(2) = 5
    LET b(3) = 1
END SUB

SUB dot(a(),b())
    LET dot_product = 0
    FOR i = 1 to 3
        LET dot_product = dot_product + a(i)*b(i)
    NEXT i
    PRINT "scalar product = "; dot_product
END SUB

SUB cross(r(),s())
    ! arrays can be defined in main program or subroutine
    ! note use of dummy variables
    DIM cross_product(3)
    FOR component = 1 to 3
        LET i = mod(component,3) + 1
        LET j = mod(i,3) + 1
        LET cross_product(component) = r(i)*s(j) - s(i)*r(j)
    NEXT component
    PRINT
    PRINT "three components of the vector product:"
    PRINT " x "," y "," z "
    FOR component = 1 to 3
        PRINT cross_product(component),
    NEXT component
END SUB
The properties of arrays in True BASIC include: Arrays are defined in a DIM statement and the total number of elements of an array is given in parentheses. The array variables a and b in the main program and the array variables r and s in SUB cross are examples of one-dimensional arrays.
 The lower and upper limit of each subscript in an array can be specified; the default lower limit is 1. Examples of other limits are DIM r(0 to 2) and DIM s(-3 to 3). A colon may be used instead of TO in the DIM statement, for example, DIM r(0:2) and DIM s(-3:3). The arguments in a DIM statement must be numbers, not variables.
 An element of an array is specified by its subscript value. Arrays can be passed to a subroutine or a function, with empty parentheses and commas used to indicate the dimension of the array.
 The same name cannot be used for both an array variable and for another type of variable.
Because the address of the first element of the array is passed, rather than the entire array, there is no memory or speed penalty when arrays are passed to a subroutine. True BASIC has many intrinsic matrix operations which are similar to the operations in F.
6. Input/output
SET CURSORPRINT USINGGET KEYGET MOUSEFilesREAD/DATA statements
The PRINT statement displays output on the screen. Some simple extensions of the PRINT statement include
PRINT "x","y","z"
PRINT x,y,z
PRINT                     ! skip line
PRINT "time ="; t
PRINT tab(7);"time";tab(17);"position";tab(28);"velocity"
 True BASIC prints at the current cursor position. The function tab(x) moves the cursor to column x.
 The cursor may be moved by the SET CURSOR statement
SET CURSOR 10, 20            ! row, column
which moves the cursor to row 10 and column 20. SET CURSOR 1,1 moves the cursor to the upper left corner. Because different computers have different numbers of rows and columns, the statement
ASK SET CURSOR max_row,max_col
sets max_row to the largest row number and max_col to the maximum column number.
Formatted output
If you need to print output to greater accuracy or in a different format than the default used by True BASIC, use the 
PRINT using statement.
PRINT using "####.###": t,x,v  ! output occupies 8 spaces including decimal point
PRINT using "----.###": t,x,v  ! - prints number with leading space or minus sign
PRINT using "--%%.###": t,x,v  ! % prints leading zeroes as '0'
Try various values of t, x, and v to see the nature of the output. For example, try t = 15.5, x = -3.222222, and v = 1.Key input
The statement GET KEY k waits until the user presses a key, then converts that key into its corresponding number and then converts this number to the variable k.
PROGRAM space_bar
DO
   GET KEY k
   PRINT k
LOOP until k = 32                 ! pressing space bar exits loop
END
We have already given an example of the use of the logical expression 
key input.Mouse
The use of the GET MOUSE statement is illustrated in Program mouse:
PROGRAM mouse
DO
   ! return current x and y window coordinates and state of mouse
   GET MOUSE x,y,s
   IF s = 1 then
      PRINT "button down",x,y
   ELSE IF s = 2 then
      PRINT "button clicked",x,y
   ELSE IF s = 3 then
      PRINT "button released",x,y
   END IF
LOOP
END
The variable s is the state of the mouse when the cursor is at position (x,y). The possible values of the status are
s = 0mouse button not pressed
s = 1mouse button held down while dragging
s = 2mouse button clicked at (x,y)
s = 3mouse button released at (x,y)
Files
The following program illustrates how to open a text file, write to the file, close the file, and read the file.
PROGRAM single_column
! save data in a single column
! file$ example of string variable
INPUT prompt "name of file for data? ": file$
! channel number #1 associated with file and can be passed to
! subroutines
! various options may be specified in OPEN statement
! access output: write to file only
! create newold: open file if exists, else create new file
OPEN #1: name file$, access output, create newold
! True BASIC does not overwrite data in a text file
! ERASE #1                          ! erase contents of file
! RESET #1: end   ! allows data to be added to end of file
FOR i = 1 to 4
    LET x = i*i
    PRINT #1: x                   ! print column of data
NEXT i
CLOSE #1
! channel # irrelevant if only one channel open at a time
OPEN #2: name file$, access input
FOR i = 1 to 4
    INPUT #2: y                   ! print column of data
    PRINT y
NEXT i
! files automatically closed when program terminates
CLOSE #2                          ! not necessary but good practice
END
Program single_column uses a 
string or character variable for the name of the file. The writing of files with multiple columns is more complicated and is illustrated in the following.
file$ = "config.dat"
OPEN #1: name file$,access output,create new
PRINT #1: N
PRINT #1: L
! comma added between inputs on the same line so that file
! can be read by True BASIC
FOR i = 1 to N
   PRINT #1, using "----.######, ----.######": x(i),y(i)
NEXT i
CLOSE #1
! next illustrate how to read file.
OPEN #1: name file$, access input
INPUT #1: N
INPUT #1: L
FOR i = 1 to N
   INPUT #1: x(i),y(i)
NEXT i
It is necessary to separate columns by a comma, an annoying feature of True BASIC. There are many variations on the open statement, but the above example is typical.READ/DATA statements
One way to incorporate data into a program from a file. Another way to store information within a program is by using the DATA and READ statements as illustrated in Program example_data.
PROGRAM example_data
DIM x(6)
DATA 4.48,3.06,0.20,2.08,3.88,3.36
FOR i = 1 to 6
    READ x(i)                ! reads input from DATA statement
NEXT i
END
7. GraphicsThe platform independent graphics statements of True BASIC are sufficiently powerful to do useful animations and visualizations. It is recommended that a separate plotting program be used for making presentation graphs and fits to data.
Core statementsAspect ratioMultiple windowsAnimation
A graphics screen is covered by a grid of pixels. The number of pixels is hardware dependent. In True BASIC the number of pixels is irrelevant because the mapping of the absolute values of the coordinates to the device coordinates or pixels is done by True BASIC. The first step is to specify the range of coordinates which are to be plotted. The statement
SET WINDOW xmin, xmax, ymin, ymax
determines the minimum and maximum x (horizontal) and y (vertical) coordinates. The statement
PLOT POINTS: x,y;
draws a point at (x,y) in the current window coordinates. The statement
PLOT LINES: x1,y1; x2,y2;
draws a line between (x1,y1) and (x2,y2). Program plot_f uses these statements to draw a set of axes and plot the function T(t) = Ts - (Ts - T0) e-rt.
PROGRAM plot_f                     ! plot analytical solution
CALL initial(t,tmax,r,Ts,T0)
CALL set_up_window(t,tmax,Ts,T0)
CALL show_plot(t,tmax,r,Ts,T0)
END

SUB initial(t,tmax,r,Ts,T0)
    LET t = 0
    LET T0 = 83                   ! initial coffee temperature (C)
    LET Ts = 22                   ! room temperature (C)
    INPUT prompt "cooling constant r = ": r
    INPUT prompt "duration = ": tmax   ! time (minutes)
    CLEAR
END SUB

SUB set_up_window(xmin,xmax,ymin,ymax)
    LET mx = 0.01*(xmax - xmin)   ! margin
    LET my = 0.01*(ymax - ymin)
    SET WINDOW xmin - mx,xmax + mx,ymin - my,ymax + my
    ! default background color black on all computers except Macintosh
    PLOT xmin,ymin; xmax,ymin     ! abbreviation for PLOT LINES:
    PLOT xmin,ymin; xmin,ymax
END SUB

SUB show_plot(t,tmax,r,Ts,T0)
    DECLARE DEF f                 ! declare use of external function
    SET COLOR "red"
    DO while t <= tmax
       PLOT t,f(t,r,Ts,T0);       ! abbreviation for PLOT LINES
       LET t = t + 0.1
    LOOP
END SUB

DEF f(t,r,Ts,T0)
    LET f = Ts - (Ts - T0)*exp(-r*t)
END DEF
The program uses a separate subroutine to set up the screen and another to plot the function. PLOT x,y; is an abbreviation of PLOT POINT x,y.
Program simple_map uses the SET WINDOW, PLOT, BOX LINES and ASK MAX COLOR statements to help visualize the trajectory of a two-dimensional dynamical system. A summary of the some of the important graphics statements is given in Table 3.


Table 3. Summary of core True BASIC graphics statements.
SET BACKGROUND COLOR "black"
SET WINDOW xmin,xmax,ymin,ymaxdefault window coordinates are 0,1,0,1
PLOT POINTS: x,yabbreviation is PLOT x,y
PLOT LINES: x1,y1; x2,y2;
PLOTstart a new curve
PLOT AREA: 1,1;2,1;2,2draw filled triangle
BOX LINES xmin,xmax,ymin,ymaxdraw rectangle
BOX AREA xmin,xmax,ymin,ymaxdraw filled rectangle
BOX CLEAR xmin,xmax,ymin,ymaxerase rectangle
BOX CIRCLE xmin,xmax,ymin,ymaxdraw inscribed circle (or ellipse)
ASK MAX COLOR mcmc is number of foreground colors
SET COLOR "red"colors include green, blue, brown, magenta, and white
CLEARerase contents of current window
FLOOD x,yfill enclosed region with current foreground color
Aspect Ratio
When is a circle not a circle? Run the following program and find out.
PROGRAM no_circle
LET r = 1                         ! radius of circle
SET WINDOW -r,r,-r,r
SET COLOR "blue"
BOX CIRCLE -r,r,-r,r
! FLOOD 0,0: start from the point 0,0 and color continuous pixels 
! until boundary of region is reached
FLOOD 0,0
END
The problem is that few computer screens are square and have the same number of pixels in the horizontal and vertical direction. Moreover, it is possible to define 
multiple windows whose shape is arbitrary. Sometimes it is essential that a circle really appear circular on the screen. In this case we must correct for the aspect ratio of the screen as done in the following program.
PROGRAM circle
LET r = 1                         ! radius of circle
CALL compute_aspect_ratio(r,xwin,ywin)
SET WINDOW -xwin,xwin,-ywin,ywin
SET COLOR "blue"
BOX CIRCLE -r,r,-r,r              ! draw circle
END

SUB compute_aspect_ratio(r,x,y)
    LET m = 0.1*r                 ! margin
    LET size = r + m
    ! px, py: # pixels in horizontal and vertical direction
    ASK PIXELS px,py
    IF px > py then
       LET aspect_ratio = px/py
       LET x = aspect_ratio*size
       LET y = size
    ELSE
       LET aspect_ratio = py/px
       LET x = size
       LET y = aspect_ratio*size
    END IF
END SUB
Note the use of the ASK PIXELS statement.
Multiple windows
So far we have used the entire screen for the default window. The following program illustrates how to use the OPEN statement to use a portion of the screen, make multiple windows, and choose a particular window. Note that each window has an associated channel number and properties such as its own coordinate system and plot color.
PROGRAM multiple_windows
! note passing of channel numbers
CALL initial(#1,#2)               ! initialize windows
CALL show(#1)
CALL show(#2)
END

SUB initial(#1,#2)
    OPEN #1: screen 0,0.5,0,1     ! left-half of screen
    SET WINDOW 0,1,0,1
    SET COLOR "green"
    OPEN #2: screen 0.5,1,0,1     ! right-half of screen
    SET COLOR "red"
    SET WINDOW 0,1,0,1
END SUB

SUB show(#9)
    WINDOW #9                     ! note use of dummy variable
    FOR i = 1 to 100
        PLOT rnd,rnd;
    NEXT i
END SUB
Animation
To make animations, we can store screen images as a 
string variable and display them again without the need for additional calculation. The following program illustrates the use of the BOX KEEP, BOX CLEAR, and BOX SHOW statements to create the illustrate the illusion of motion across the screen.
PROGRAM animation
SET WINDOW 1,10,1,10
SET COLOR "red"
BOX AREA 1,2,1,2             ! draw shape
BOX KEEP 1,2,1,2 in box$     ! store shape in string variable box$
CLEAR
LET x = 1
DO while x < 10
   BOX CLEAR x,x+1,5,6       ! erase shape
   LET x = x + 0.1
   BOX SHOW box$ at x,5      ! redraw shape at different location
   PAUSE 0.01                ! choose delay
LOOP
END
Another example of the use of animation is shown in Program pendula.8. String variablesAs mentioned, True BASIC recognizes only two types of variables, numeric and strings. A string variable may be any combination of characters. String variables end in a dollar sign ($). A string constant is any list of characters enclosed in quotation marks. An example of an assignment of a string variable is
LET file_name$ = "config.dat"
A program illustrating the most common operations on string variables follows:
PROGRAM string
LET a$ = " "
LET b$ = "good"
PRINT b$
LET b$ = b$ & a$ & "morning"     ! & for concatenation
PRINT b$
LET c$ = b$[1:4]                  ! extract substring
PRINT c$
END
True BASIC has many useful string handling functions, some which are summarized in Table 4.
Table 4. Useful string handling functions.
notationfunction
len(x$)number of characters in x$
pos(x$,a$,c)first occurrence of a$ in x$ at or after character number c
lcase$(x$)convert letters to lower case
ucase$(x$)convert letters to upper case
trim$(x$)remove leading and trailing blanks
ltrim$(x$)remove leading blanks
rtrim$(x$)remove trailing blanks
The function str$ converts a number to a string. The function val converts a string to a number. An example of the use of str$ is given in the following program.
PROGRAM read_file
! open n successive files
LET n = 20
FOR i = 1 to n
    LET si$ = str$(i)
    LET file_name$ = "config" & si$ & ".dat"
    OPEN #i: name file_name$, access output, create newold
    PRINT #i: file_name$
    PRINT file_name$
    CLOSE #i
NEXT i
END
9. Advanced topics
RecursionGlobal variablesStrong typingmodulesSelect caseMatrix operations
Recursion
A simple example of a recursive definition is the factorial function
factorial(n) = n! = n(n-1)(n-2) ... 1
A recursive definition of the factorial is
factorial(n) = n factorial(n-1)
A program that closely parallels the above definition follows.
PROGRAM n!
DECLARE DEF f
LET n = 11
PRINT "n! ="; f(n)
END PROGRAM

DEF f(n)
    IF n <= 0 then
       LET f = 1
    ELSE
       LET f = n*f(n-1)
    END IF
END DEF
Global variables
So far we have shared information between subprograms by using a parameter list. Another way to share information is by declaring variables to be PUBLIC. An example illustrates its use.
PROGRAM show_public
PUBLIC L,spin(3,3)
CALL initial
FOR y = 1 to L
    FOR x = 1 to L
        PRINT spin(x,y);
    NEXT x
    PRINT
NEXT y
END

SUB initial
    DECLARE PUBLIC L,spin(,)
    LET L = 3
    FOR y = 1 to L
        FOR x = 1 to L
            IF rnd < 0.5 then
               LET spin(x,y) = 1
            ELSE
               LET spin(x,y) = -1
            END IF
        NEXT x
    NEXT y
END SUB
Strong typing
Unlike C, F, and Java, True BASIC does not require variables to be declared before they can be used. The enforced declaration of variables is called strong typing and can be "turned on" in True BASIC by using the OPTION TYPO statement. This statement requires all variables to be declared as either LOCAL, PUBLIC or passed. Public variables are not passed in the arguments of the subroutines.
PROGRAM show_public
OPTION TYPO
PUBLIC L,spin(3,3)
LOCAL x,y
CALL initial
FOR y = 1 to L
    FOR x = 1 to L
        PRINT spin(x,y);
    NEXT x
    PRINT
NEXT y
END

SUB initial
    DECLARE PUBLIC L,spin(,)
    LOCAL x,y
    LET L = 3
    FOR y = 1 to L
        FOR x = 1 to L
            IF rnd < 0.5 then
               LET spin(x,y) = 1
            ELSE
               LET spin(x,y) = -1
            END IF
        NEXT x
    NEXT y
END SUB
Modules
A module is a library of external subprograms. If you are ready to use a module, you are ready to learn another procedural language such as 
F which uses modules more effectively. An example of a True BASIC program which uses a module follows.
PROGRAM cool
! numerical solution of Newton's law of cooling
LIBRARY "common"
DECLARE PUBLIC r,t,dt,tmax,nshow,T_coffee
CALL output
LET counter = 0
DO
   IF (t >= tmax) then
      EXIT DO
   END IF
   CALL Euler
   LET counter = counter + 1      ! number of iterations
   IF (mod(counter,nshow) = 0) then
      CALL output
   END IF
LOOP
DO
LOOP until key input
END
The module "common" is in a separate file with the same name. PUBLIC statements determine which variables may be accessed from outside the module. SHARE statements determine the variables that are available to all subprograms within the module, but not outside the module.
MODULE common
    PUBLIC r,t,dt,tmax,nshow,T_coffee
    SHARE T_room

    ! initialize variables
    LET t = 0.0                   ! time
    LET T_coffee = 82.3           ! initial coffee temperature (C)
    LET T_room = 17.0             ! room temperature (C)
    LET r = 0.2
    LET dt = 0.01
    LET tmax = 1
    LET tshow = 0.1
    LET nshow = int(tshow/dt)

    SUB Euler
        LET change = -r*(T_coffee - T_room)*dt
        LET T_coffee = T_coffee + change
        LET t = t + dt
    END SUB

    SUB output
        IF t = 0 then
           PRINT
           PRINT  "time","T_coffee","T_coffee - T_room"
           PRINT
        END IF
        PRINT t,T_coffee,T_coffee - T_room
    END SUB

END MODULE
Select case
If all the choices in the decision structure are based on the value of a single expression, it is sometimes convenient to use a SELECT CASE structure instead of multiple ELSEIF statements. An example of the use of the SELECT CASE structure in the context of a two-dimensional random walk follows:
LET direction = int(4*rnd) + 1
SELECT CASE direction
CASE 1
     LET x = x + 1
CASE 2
     LET x = x - 1
CASE 3
     LET y = y + 1
CASE 4
     LET y = y - 1
CASE else
     PRINT "error"
END SELECT
Matrix operations
True BASIC has many operations which operate on an entire array at once. MAT READ, MAT INPUT, and MAT PRINT have obvious meanings. Arrays in which all the elements are the same may be established as follows:
DIM usave(0:21)
MAT usave = 1.0
Matrix arithmetic such as adding matrices and dot products can be done as illustrated in the following program. Add some MAT PRINT statements to check the results.
PROGRAM example_matrix
! illustrate simple matrix arithmetic
DIM A(4),B(4),C(4),S(2,2),T(2,2),SI(2,2)
MAT A = 1
MAT B = 2*A
MAT C = A + B
MAT PRINT A,B,C
LET dot_product = dot(A,B)        ! dot product of A and B
MAT C = A*B                       ! matrix product
DATA 1,3,4,8
MAT READ S
MAT PRINT C,S
MAT T = Trn(S)                    ! transposed matrix
MAT SI = Inv(S)                   ! inverse matrix
MAT PRINT T,SI
! check that matrix of most recently inverted matrix is not too small
print det
END
True BASIC also allows arrays to be redimensioned in a way similar to the use of the allocate and deallocate statements in 
Fortran 90. But if you have read this far, you are ready to learn Fortran and C.


background image
C Aptitude Questions 


01) 
Which header file should  you include if  you  are to develop a function that can   accept 
variable number of arguments? 

a) Vararg.h 
 
 
 
 
b) stdlib.h 
c) stdio.h 
 
 
 
 
d) stdarg.h 

02) 
 In a ‘C’ program, constant is defined 
 
a)
  before main. 
 
 
 
b) after main. 
c)
  anywhere, but starting on a new line. 
d) none of the above. 

03)   
printf(“%d”.printf(“tim*)); 
 
a) result in a syntax error. 
 
 
b) outputs tim3. 
c) output garbage. 
 
 
 
d) prints tim and terminates abruptly. 

04) 
The rule for implict type conversion in ‘C’ is 
 
a) int<unsigned<float<double. 
 
b) unsigned<int<float<double. 
c) int<unsigned<double<float. 
 
d) unsigned<int<double<float. 

05) 
Which of the following statements is correct? 
 
a)
  C provides no input-output features. 
 
b)
  b) C provides no file access features. 
c) provides no features to manipulate composite objects.
d) all of the above. 

06) 
Integer division in a ‘C’ program results in 
 
a)truncation.   
 
 
 
b) rounding. 
c) overflow.   
 
 
 
d) none of the above. 
 

07)  
For ‘C’ programming language,which of the following statements is (are) true ? 
 
a) Constant expression are evaluated at compile time.
b) String constants can be concatenated at compile time.
c) Size of the array should be known at compile time.
d) all of the above. 


 
Answers
background image
08) 
In a ‘C’ expression involving || operator, evaluation 
 
a)
  will be stopped if one of its components evaluates to false. 
b) will be stopped if one of its components evaluates to true.
c) takes place from right to left.
d) takes place from left to right. 

09) 
Which of the following statements is (are) correct ? 
 
a) enum variables can be assigned new values.
b) enum variables can be compared.
c) enumeration feature does not increase the power of C.
d) all of the above. 
 
      10) 
Which  of  the  following  comments  regarding  the  reading  of  a  string,using  scanf  (with 
option) and gets is true ? 
 
a)
  Both can be used interchangeably. 
b) scanf is delimited by end of line, while gets is not
c) scanf is delimited by blank , while gets is not.
d) none of the above. 

11) 
Which of the following comments about the ++ operator is (are) correct? 
 
a)
  It is unary operator. 
b)
  The operand can come before or after the operator. 
c)
  It can not  be applied to an expression. 
d)
  It associates from the right. 
e)
  all the above. 

12) 
When a variable of data type double is converted into float then 
 
a)
  rounding takes place. 
b)
  truncation takes place. 
c)
  the lower order bits are dropped. 
d)
  none of the above. 


13) 
Which of the following C statements is syntactically correct? 
 
a) for(); 
 
 
b) for(;); 
c) for(,); 
 
 
d) for(;;); 


14)
    Consider for loop in a C program.If the condition is missing 
 
Answers
background image
a)
  it is assumed to be present and taken to be false. 
b)
  it is assumed to be present and taken to be true. 
c)
  it results in a syntax error. 
d)
  execution will be terminated. 
15) 
Which of the following statements about for loop are correct? 
 
a)
  index value is retained outside the loop. 
b)
  index value can be changed from within the loop. 
c)
  Goto can be used to jump,out of the loop. 
d)
  All of the above. 

16) 
Arrays can be initialized provided they are 
 
a)
  Automatic.  
 
b)External. 
c)   Static. 
 
 
d)Both (2) and (3) above. 

17)| 
Arrays are passed as arguments to sa  function by 
 
a)
  value. 
 
 
b) Reference. 
c) both (1) and (2) above. 
d) none of the above. 

18) 
It is necessary to declare the type of a function in the calling program if 
 
a)
  the function returns an integer. 
b)
  the function returns a non-integer value. 
c)
  the function is not defined in the same file. 
d)
  none of the above. 

19) 
The declaration void function 1(int)indicates the function 1 is a function which 
 
a)
  has no arguments. 
b)
  returns nothing. 
c)
  both(1) and (2) above. 
d)
  None of the above. 

20) 
Recursive functions are executed in a 
 
a)
  Last in first out order. 
b)
  First in first out order. 
c)
  Parallel fashion. 
d)
  all of the above. 

21) 
When a function is recursively called,all automatic variables 
 
a)
  are initialized during each execution. 
b)
  are retained from the last execution. 
Answers
background image
c)
  are maintained in a stack. 
d)
  none of the above. 

22) 
A static variable 
 
a)
  cannot be initialized. 
b)
  is initialized once at the commencement of execution and cannot be changed at run 
time. 
c)
  retains its value throughout the file of the program. 
d)
  is same as an automatic variable but is placed at the head of a program. 

23) 
An external variable 
 
a)
  is globally accessible by all functions 
b)
  has a declaration “extern” associated with it when declared within a function. 
c)
  will be initialized to 0 if not initialized. 
d)
  all of the above. 

24) 
A “switch” statement is used to 
 
a)
  switch between functions in a program. 
b)
  switch from one variable to another variable. 
c)
  to  choose  from  multiple  possibilities  which  may  arise  due  to  different  values  of  a 
single variable. 
d)
  to use switching variable. 

25) 
The statement #include<math.h>is written at the top of a program to indicate 
 
a)
  the beginning of the program. 
b)
  the program does heavy mathematical calculations 
c)
  that certainly information about mathematical library functions are to be included at 
the beginning of the program. 
d)
  none of the above. 

26) 
What is the output of the following ‘C’ program?
main( )
{
extern int I;
i=20;
printf(“%d”,sizeof(i)); 
 
a)
  2 
b)
  4 
c)
  would vary from compiler to compiler. 
d)
  Error, i underdefined. 
Answers
background image
27) 
What is the output of the following ‘C’ program?
main( )
{
extern int a;
printf(“\n%d”,a);
}
int a=20; 
 
a)
  0 
b)
  20 
c)
  Error. 
d)
  Garbage value. 


28) 
 What is the output of the following ‘C’ program? 
 
main( )
{
extern int fun(float);
int a;
a=fun(3.14);
printf(“%d”,a);
}
int fun(aa);
float aa;
{
return ((int)aa);
 
a)
  3.14 
b)
  3.0 
c)
  0 
d)
  Error. 



29) 
What is the output of the following ‘C’ program? 
 
main( )
{
int a[5]={2,3};
printf(“\n%d %d %d”,a[2],a[3],a[4];
 
a)
  Garbage values. 
b)
  2 3 3 
Answers
background image
c)
  3 2 2 
d)
  0 0 0 





30) 
What is the output of the following ‘C’ program? 
 
main( )
{
Struct emp
{
char name[20];
int age;
flat sal;
};
struct emp e={“Tiger”};
printf(“\n%d%d%f”,e.age,e.sal); 
 
a)
  Error. 
b)
  Garbage value 
c)
  00.0000000 
d)
  10.000000 

31) 
In the following ‘C’ program,find the error,if any? 
 
main( )
{
int i=1;
for(; ;)
{
printf(“%d”,i++);
if(i>10)
break;
}
}
a)
  The condition is in the for loop is must. 
b)
  the two semicolons should be dropped. 
c)
  the for loop should be replaced by a while loop. 
d)
  No error. 

32) 
In the following  ‘C’ program,find out the error in the ‘while’ loop,if any ?
main( )
{
int i=1; 
Answers
background image
While( )
{
printf(“%d”,i++);
if(i>10)
break;
 
a)
  the condition in the while loop is a must. 
b)
  there should be atleast a semicolon in the while( ). 
c)
  the while loop should be replaced by for loop. 
d)
  No error. 

33) 
 What is the output of the following ‘C’ program? 
 
main( )
{
int i=2;
printf(“\n%d%d”,++i,++i);
 
a)
  3  4 
b)
  4  3 
c)
  4  4 
d)
  output may vary from compiler to compiler. 

34) 
What is the output of the following ‘C’ program? 
 
main( )
{
int x=10,y=10,z=5,i;
i=x<y<z;
printf(“\n%d”,i);
 
a)
  1 
b)
  0 
c)
  Error. 
d)
  5 

35)  
Consider the following ‘C’ statement.what is the order in which functions are  called?
A=f1(23,14)*f2(12/4)+f3(); 
 
a)
  f1,f2,f3 
b)
  f3,f2,f1 
c)
  the order may vary from compiler to compiler. 
Answers
background image
d)
  None of the above. 

36) 
In the following ‘C’code in which order the functions would be called?
a= (f1(23,14)*12(12/4))+f3(); 
 
a)
  f1,f2,f3 
b)
  f3,f2,f1 
c)
  The order may vary from compiler to compiler. 
d)
  None of the above. 



37) 
 What is the output of the following ‘C’ program? 
 
main( )
{
float a=0.7;
if(a<0.7)
printf(“C”);
else
Printf(“C++”);
 
a)
  C 
b)
  C++ 
c)
  Error. 
d)
  None of the above. 

38) 
 What is the output of the following ‘C’ program? 
 
main( )
{
float a=0.7;
if(a<0.7f)
printf(“C”);
else
printf(“C++”);
 
a)
  C   
 
b)C++ 
b)
  Error 
 
d)None of the above. 

39) 
What is the output of the following ‘C’ program? 
 
main( )
Answers
background image
printf(“%f”,sqrt(36.0));
 
a)
  6.0 
b)
  6 
c)
  6.000000 
d)
  Some absurd value. 

40) 
We want to round off x,a float, to an int value.What is the correct way to do so? 
 
a)
  y=(int)(x+0.5) 
b)
  y=int(x+0.5) 
c)
  y=(int) x+0.5; 
d)
  y=(int)((int)x+0.5). 


41) 
What error are you likely to get when you run the following program? 
 
main( )
{
struct emp
{
char name[20];
float sal;
}
struct emp-e[10];
int I;
for(i=0;<=9;i++)
scanf(“%s%f”,e[i].name,&e[i].sal); 
 
a)
  Suspicious pointer conversion 
b)
  Floating pint formats not linked 
c)
  Cannot use scanf( )for structures. 
d)
  Strings cannot be nested inside structures. 

42) 
By default any real number in C is treated as 
 
a)
  a float 
b)
  a double 
c)
  a long double 
d)
  Depends upon the memory model that you are using. 

43) 
 What is the output of the following ‘C’ program? 
 
main( )
Answers
background image
pritnf(“%d%d%d”,sizeof(3.14f),sizeof(3.14),sizeof(3.14I));
 
a)
  4 4 4 
b)
  4 Garbage value 
c)
  4 8 10 
d)
  Error 

44)       If the binary equivalent of 5.375 in normalized form is 0100 0000 1010 1100  0000 0000 
0000,0000 what is the output of the following program ? 
 
main( )
{
float a=5.375;
char *p;
int I;
p=(char *)&a;
for(i=0;i<=3;i++)
Printf(“%02x”,(unsigned char)p[i];);
 
a)
  40 AC 00 00 
b)
  00 CA 00 40 
c)
  00 00 Ac 40 
d)
  00 00 CA 04 

45) 
What error would the following function given on compilation ? 
 
f(int a,int b)
{

int a;
a=20;
return a;
 
a)
  Missing parantheses is return statement 
b)
  The function should be defined as int f(int a, int b) 
c)
  Redeclaration of a 
d)
  None of the above. 

46) 
How many times the following ‘C’ program would print ‘Jamboree’ ? 
 
main( )
{
printf(“\nJamboree”); 
Answers