1. Give the decimal value of each binary number.

    1. 10011=
      1. 17
      2. 19
      3. 14
      4. 21
    2. 110101=
      1. 50
      2. 51
      3. 48
      4. 53

  2. Give the binary value for each decimal number.

    1. 29=
      1. 11001
      2. 10111
      3. 11101
      4. 11011

    2. 81=
      1. 1010001
      2. 1010101
      3. 1010011
      4. 1011110

  3. The integer ADT describes arithmetric and relational operations. Compute following expressions.
    int x=42, y=9, z;
    1. z=x/y=____
    2. z=x%y=____
      Assume the logical value TRUE is assigned the value 1 and FALSE is assigned the value 0.
    3. y=(!5<3)+5*(4<6)=_____
    4. y=!(5<3)*9-!(16%4)=_____

  4. Assume an integer is stored in memory as a 16-bit(2 byte) value and an ASCII character representation, `0' = 48, `A' = 65 and `a'=97. Use these initial range values.
    1. What character corresponds to the decimal number 76?_____
    2. what character corresponds to the binary number 11000112? ____.
    3. What is printed by the following output statement?____
      	  cout<<char(100)<<" "<< int (`C')<< " "
      
      <<(int(`1')+3) << endl;

      The following is a four bytes sequence of characters beginning at address 100. Use the data to answer questions D-E.

    4. What are the data values when memory is used as four consecutive characters?
      1. defg
      2. Bb2E
      3. bCE2
      4. Ba4F

    5. What are the data values when memory is viewed as a character followed by an integer and a character? OL TYPE=a>
    6. B6232F
    7. b6233E
    8. b6232F
    9. B6232E

  5. Convert the fixed point binary number to decimal. 1010.101=____.

  6. Convert the fixed point decimal number 4.1875 to binary.
    1. 100.0101
    2. 100.00101
    3. 100.0011
    4. 101.01101

  7. Assume the following declaration of an enumerated type.
    enum DaysOfWeek{Sun, Mon, Tues, Wed, Thurs, Fri, Sat};
    1. What is DaysOfWeek(3)?__
    2. What is DaysOfWeek(8)?__
    3. Assume d is a variable of type DaysOfWeek and d=Thurs. What is the value of the expression int(d)-3?___
    4. Can the type DaysOfWeek and newDaysOfWeek be used interchangeably?___
      enum newDaysOfWeek{Sat,Sun, Mon, Tues, Wed, Thurs, Fri};
      1. yes
      2. no
    5. We want Sun to be the first day of the week and also have the value 1. What is the correct declaration of type DaysOfWeek?___
      1. enum DaysOfWeek{,Sun, Mon, Tues, Wed, Thurs, Fri, Sat};
      2. enum DaysOfWeek{" ",Sun, Mon, Tues, Wed, Thurs, Fri, Sat};
      3. enum DaysOfWeek{Sun=1, Mon, Tues, Wed, Thurs, Fri, Sat};
      4. enum DaysOfWeek{Sat, Sun, Mon, Tues, Wed, Thurs, Fri};

  8. Use the following declarations for each questions, identify the output for each part.
    int X=20, Y=5, *PX=&X, *PY; int A[]={2, 4, 8, 1, 5, 3}, *PA=A;
    1. cout << (*PX)+3; //output=____
    2. PY=PX; *PY+=*PX*Y; cout<<X; //output=____
    3. cout<<*PA //output=____
    4. cout<< (*PA+3) //output=____
    5. PA++; cout<< *++PA; //output=____
    6. PA+=2; *PA+=3; cout<< *PA; //output=____

  9. Assume a short(int) is stored in 2 bytes, a long(int) is stored in 4 bytes and a character is stored in 1 byte.
    1. How many bytes are allocated by the declaration of each array?
      short A[9]; // byte allocation for array A ____.
      long b[250]; // byte allocation for array B ____.
    2. If the starting address of the array A is 500, what is the address of element A[7]?
      1. 507
      2. 514
      3. 512
      4. 563
    3. If the starting address of array B is 1210, which array element is located at address 1294.
      1. B[94]
      2. B[23]
      3. B[84]
      4. B[21]
  10. The record DataRec is defined as a C++ struct.

    struct DataRec

    {
         int one;
         long two;
         double three;
         char four[30];
         };
         DataRec arr[]={{1, 3, 5.6, "ABC"}, {6, 8, 34.5, "def"}, {5, 7, -106.56, "ghijk"}}, *p=arr;
    
    1. What is output from the statement_____.
      cout << p->one << endl ;
    2. Execute the two statements and then identify the output.
      p++; cout << (*p).two << " " << p-> three << endl;
      The output is ____ ____
    3. What is output from the statement____
      cout << (*(p+2)).four<<endl;

  11. Use the following declarations for each question.

    char str1[32]="string one", str2[32], str3[33]; char c;

    1. How many characters are used to store str1?____
      1. 11
      2. 10
      3. 6
      4. 7
    2. What is the value for the statement strlen(str1)?____
      1. 11
      2. 10
      3. 6
      4. 7
    3. Execute the following input statements

      cin >> str2;
      cin.get(c);
      cin.getline(str3, 33, `\n');
      

      What are the resulting contents of str2 and str3 for input "C++ String Library"
      str2= ____ C++ String ______ str3=____ Library____.

  12. Trace the code and answer the questions.
    #include <iostream.h>
    #include < string.h>
    
    void main(void)
    
    {
    char line[32], *chptr, *fnptr;
    char delimiter;
    int i=0;
    
    cin.getline(line, 32, '\n');
    cout << "Delimiter character";
    cin >> delimiter;
    
    chptr=strchr(line, delimiter);
    *chptr='\0';
    
    fnptr=chptr+1;
    chptr=strchr(fnptr, delimiter);
    *chptr++ = '.';
    
    strcat(chptr, "xxx");
    
    cout << line;	//output #1
    cout << fnptr;	// output #2
    }
    
    Assume the input is "Jones:465-29-8153:home" and the delimiter character is ':'
    1. Output #1 is ____
    2. Output #2 is ____
  13. C++ strings use the NULL character to terminate the array. An alternative method places the character count as the first element of the character array. This is called a byte count format. The following are ASCII values.
    NULL=0, BEL=7, LF=10, '0'=48, 'A'=65, 'a'=97
    String STR has the following array of characters with their ASCII values.
    765666768050519798990
    1. What is the byte count version of string STR?___
    2. What is the C++ version of string STR?___

  14. Disk files that include both binary and text files use the class ____.
    1. bintxtstream
    2. fdisk
    3. fstream
    4. diskstream

  15. Indicate whether each file is a text or pure binary file.

    1. C++ code
      1. text
      2. binary

    2. Executable code
      1. text
      2. binary
    3. File
      1. text
      2. binary

  16. An istrstream object gets its input data from what data structure?_____

  17. Trace the program and give the output.
    #include <iostream.h>
    #include <strstream.h>
    
    void main(void)
    {
    	char streamchar[32]="40TNT 5.50 12.25";
    	istrstream istr(streamchar, sizeof(streamchar));
    	int i, j, k;
    	float a, b, c;
    	char ch1, ch2, ch3;
    	char str[8];
    
    	istr >> i;	cout << i << endl;	//output 1=____
    	istr >> str;	cout << str << endl; //output 2=___
    	istr >> ch1;	cout << ch1 << endl; // output3=___
    	istr>> a;		cout << a << endl;	// output 4=___
    	istr>> ch2;	cout << ch2 << endl; //output 5=___
    	istr>> j;		cout << j << endl; //output 6=____
    	istr>> b;		cout << b << endl; //output 7=___
    }
    

  18. Trace the program and give the output.
    #include <iostream.h>
    #include <string.h>
    
    char *Retr(char *list, int n, char k)
    	{
    		int i;
    		char *p;
    		
    		for (i=0 p=list; i<n;i++,p++)
    			if(*p==k)
    				return p;	//return pointer
    		return NULL;
    	}
    void main(void)
    	{
    		char *str="c:/cplus/include", *p=str, *q;
    
    		while ((q=Retr(p, strlen(p),'/'))!=NULL)
    		{
    			*q='\0';
    			cout << p << " ";
    			p=q+1;
    		}
    		cout << p << endl	// Output Statement
    	}
    
    Give the output from the cout statement. ____

  19. Trace the program and give the output.
    #include <iostream.h>
    
    void main(void)
    {
    	char str[]="pacific";
    	int i= 0;
    
    	while (str[i]!=0)
    	{
    		if (str[i]<'f')
    			str[i++]+=1;
    		else
    			str[i++]-=1;
    	}
    	cout << "Resulting string is "<< str << endl; 
    						//Output statement.
    }
    
    Output is ____

  20. Trace the code and answer the questions.
    #include<iostream.h>
    #define NULL 0
    
    char *ri(char *sp, char c)
    {
    	char *r=NULL;
    	
    	do
    		if(*sp==c)
    			r=sp;
    	while(*sp++);
    	return(r);
    }
    
    void main(void)
    {
    	char ch='s';
    	char line[80], *l;
    
    	cin.getline(line, 80, '\n');	//Reads a null terminated string
    	l=ri(line, ch);
    	cout << *l << *(l+1) << endl;
    
    }
    
    1. For input "mississippi" the output is
      1. ss
      2. is
      3. si
      4. ip
    2. For input "sampson" the output is
      1. sa
      2. ps
      3. ss
      4. None of these.

  21. The IEEE floating point format stores the sign of the number separately and stores the exponent and mantissa as unsigned numbers. A normalized form N adjusts the floating point number to have a single non-zero digit to the left of the binary point.

    N=± 1.d1d2.....dn-1x 2e

    Sign The leftmost bit is used for the sign. A "+" has 0 sign bit, and a "-" has a 1 sign bit.
    Exponent The exponent is stored in 8 bits in "excess-127" notation.
    Mantissa The mantissa takes the normalized form and stores the binary digits. The leading 1 digit is hidden.

    1. Record the number in 32-bit IEEE floating point notation. -0.5=___
    2. What is the decimal value of the 32-bit IEEE formatted number 3E000000=____.

Solutions