Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
96 views7 pages

CS Solved

Download as docx, pdf, or txt
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 7

Solved Question Paper (Computer Science)

Question No. 1: Write for a loop to populate array userGuesses with NUM_GUESSES integers. Read
integers using scanf. Ex: If NUM_GUESSES is 3 and user enters 9 5 2, then the output should be (9, 5, 2)

Question No.-2: Modify the following SQL command so that the rep_ID column is the primary key for the
table and the default value of Y is assigned to the column isActive:

CREATE TABLE store_reps(


rep_ID NUMBER(5),
lastNamevarchar(30),
firstNamevarchar(30),
isActive char(1));

Question No.-3: Write code for a function in C++ naming it reverseDigitwhich takes a positive or negative
integer value as a parameter and returns the number with its digits reversed.
For example the value of reverseDigit(532) should be 235 and if reverseDigit(-532) should be -235 .

Question No.-4 State the difference between the single-byte and burst modes in terms of the CE signal.

Question No.-5 Prove that if an edge is removed from a tree, the resulting graph is not a tree.
Answer No.-1:

importjava.util.Scanner; /*imported scanner class to read input from keyboard */


public class StoreGuesses { /*created class with StoreGuesses */
public static void main (String [] args) { /*created main method initialize programme*/
Scanner scnr = new Scanner(System.in); /*created scanner object with scnr name*/
finalint NUM_GUESSES = 3; /*created integer variable NUM_GUESSES */
int[] userGuesses = new int[NUM_GUESSES]; /*created an array object userGuesses*/
int i; /*created integer variable i*/
for(i = 0; i <userGuesses.length; ++i){ /*takes input (here i.e. 3)length from
NUM_GUESSES and store it in user.Guesses one by
one*/
userGuesses[i] = scnr.nextInt();
}
for (i = 0; i <userGuesses.length; ++i){
System.out.print(userGuesses[i] + " "); /*prints scanned input received from keyboard*/
}
}
}
Answer No.-2:

CREATE TABLE store_reps (


rep_IDint(5),
lastNamevarchar(30),
firstNamevarchar(30),
isActive char(1)DEFAULT 'Y' ,
PRIMARY KEY (rep_id));

Here in the table to assign a default value to the column (isActive) we have used the keyword DEFAULT and
assigned the default value in single quotes. In order to declare a column as primary key, the PRIMARY KEY
keyword is used and in the round brackets the name of the column is passed as an argument.
Answer No.-3:
Firstly we have to study the Mathematical concepts for reverse a number.
Let we have 532 so mathematically we can have convert it into 235 using following steps
Step1: We have to find modulus of 532
As the base of general number system is 10.
So
532 mod 10=2(say remainder)
Step 2: Let we have n=0
And n=n*10+remainder
We get n=0+2=2
Now we have 532/10=53.2
Its integer part is 53.

So now repeat step 1


53(user entered value is turned in 53 using above steps) mod 10=3
And using step2
n=n*10+remainder
n=2*10+3=23

and now 53/10=5.3 and integer part is 5.


So now repeat step 1
2 mod 10=2
And using step2
n=n*10+remainder
n=23*10+5=235

As we know the mod 10 will not convert the sign, This coding also valid for negative integer
So the C++ coding is

#include <iostream>
using namespace std;

int main()
{
int n, revNumber = 0, remainder;

cout<< "Enter an integer: ";


cin>> n;

while(n != 0)
{
remainder = n%10;
revNumber = revNumber*10 + remainder;
n /= 10;
}
cout<< "Reversed Number = " <<revNumber;

return 0;
}
Answer No.-4:

In Accessing SPI devices, we have two modes of operation, Single – byte and multibyte, We WILL Explain
each one Separately,
Single- Byte write
The following steps are used to send (write) data in single-byte mode for SPI devices, as shown in fig 16.2:
1. Make CE – 1 to begin writing.
2. The 8-bit address is shifted in one bit at a time, with each edge of SCLK, Notice that A7=1 for the
write operation, and the A7 bit goes in first,
3. After all 8 bits of the address are sent in, the SPI devices expects to receive the data belonging to
that address location immediately.
4. The 8-bit data is shifted in one bit at a time, write each of the SCLK.
5. Make CE-0 to indicate the end of the write cycle.

Figure : SPI Singlr byte Write Timing (Notice A7-1)


Multibyte burst write
Burst mode writing is an effective means of loading consecutive locations. In burst mode, we provide the
address of the location, followed by the data for that location. From then on, while CE-1, consecutive bytes
are written to consecutive memory location as long as CE is HIGH , The following steps are used to send
(write) multiple bytes of data in burst mode for SPI device as shown in Figure.
1. Make CE-1 to begin writing.
2. The 8-bti address of the first location is provided and shifted in one bit at the time , with each of
SCLK, Notice thatA7-1 for the write operatio and the A7 bit goes in first.
3. The 8- bit data for the first location is provided and shifted in one bit at a time, with each edge of the
SCLK, From then on, we simply provide consecutive bytes of data to be placed in consecutive
memory locations, In process, CE must stay high to indicate that this is a burst mode multibyte write
operation,
4. Make CE=0 to end writing.

Figure : SPI Burst (Mutibyte) mode writing


Answer No.-5:

As the definition of tree - A connected graph (Let G) without any circuit is called a Tree. As well as
we have to understand two main properties to understand this question
First -Any two vertices in G can be connected by a unique simple path.
Second-G is connected but would become disconnected if any single edge is removed from G.
Let us study given below Tree (This graph is said to be tree as there is no circuit in this graph):

If we delete (hg) edge, Tree is converted into two components.

Now we observed that the resulting graph is not a tree as we above studied ‘A connected graph (Let G)

without any circuit is called a Tree’. So it is now disconnected so does not fulfil tree definition.

You might also like