NEB 2077 computer science questions and solutions
------------------------------------------------------------
Questions:
Subject:computer science
Time:1:30hrs
Full marks:30
Group-A(2x7.5=15)
Attempt any two questions.
q1.Define array.WRite a program to sort ten integer numbers in ascending order and print them.[2+5.5]
q2.Explain function with example.Write a program to demonstrate any two string functions in C.[2+5.5]
q3.
a)Describe pointer with example.[4]
b)Explain while loop with example.[3.5]
Group-B(3x5=15)
Attempt any three questions.
q4.Describe 1N,2N and 3N normalization concept to database design.[5]
q5.compare star and ring topology.[5]
q6.What is variable?List the major data types used in C program.[2+3]
q7.What is A.I.Describe the applications of AI.
--------------------------------------------------------------------------------
Answers:-
Group-A(2x7.5=15)
Attempt any two questions.
q1.Define array.WRite a program to sort ten integer numbers in ascending order and print them.[2+5.5]
Ans:-
Array:-
An array is a collection of similar types of data items treated as a single unit. It acts to store related data under the same name with an index, also known as a subscript which helps to access individual array elements. Array data type may be int, float, char etc, depending upon the nature of problems.Features:
- It is easier for handling similar types of data in a program.
- It is efficient for solving problems like sorting, searching, indexing etc.
- It is very close to matrix, therefore it is easy for solving matrix related problems.
- Graphic is an array of pixels, so graphics manipulation can be easily done using an array.
example:
one dimensional:-int a[10]
multi dimensional:int a[2][2]
second part:
/* program to sort ten integer numbers in ascending order and print them.
*/
#include <stdio.h>
int main()
{
int numbers[100];
int n,i,j,k;
printf("enter the size of n\n");
scanf("%d",&n);
printf("Enter numbers\n");
for(i=0;i<n;i++)
{
scanf("%d",&numbers[i]);
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(numbers[i]>numbers[j])
{
k=numbers[i];
numbers[i]=numbers[j];
numbers[j]=k;
}
}
}
printf("numbers in ascending order are=:\n");
for(i=0;i<n;i++)
{
printf("%d\n",numbers[i]);
}
return 0;
}
q2.Explain function with example.Write a program to demonstrate any two string functions in C.[2+5.5]
Ans:-
Function:-
A function has 4 elements.
1. Function Declaration (Function Prototype)
2. Function Call
3. Function Definition
For example,
#include<string.h>
void main()
{
char string[100]="apple";
int k;
k=strlen(string);
printf("length=%d",k);
}
q3.
a)Describe pointer with example.[4]
Ans:-
Pointer:-
A pointer is a variable that stores a memory address. Pointers are used to store the addresses of other variables or memory items. Pointers are very useful for another type of parameter passing, usually referred to as Pass By Address. Pointers are essential for dynamic memory allocation.
Features:
1.It handles memory effectively.
2.Useful in file handling
3.Reduces spaces.
4.REduces execution time.
Example:
#include<stdio.h>
int main()
{
int *k;
int m=90;
k=&m;
printf("address=%d",k);
printf("value=%d",*k);
return 0;
}
here , k is a pointer and will store address of a variable m. It is then printed using printf(). To print its value we have to use indirection operator.
b)Explain while loop with example.[3.5]
Ans:-Let's understand while loop with the help of following points.
In the while loop, condition is
checked in the beginning. |
It is also known as a pre-test or
entry control loop. |
It is not terminated with a
semicolon. |
In the while loop, statements are
not executed if the condition is false. |
It uses the keyword ‘while’. |
The syntax of while loop is as
follows: initialization; while(condition) { statements; increment/decrement; } |
The operation of while loop can be
represented using flowchart as follows: |
Example: int main() { int i=1; while(i>=10) { printf("I
love my country"); i++; } return 0; } Output: This program displays nothing as output; as condition is
evaluated false in the beginning. |
Group-B(3x5=15)
Attempt any three questions.
q4.Describe 1N,2N and 3N normalization concept to database design.[5]
Ans:-
In the field of relational database design, normalization is a systematic way of ensuring that a database structure is suitable for general-purpose querying and free of certain undesirable characteristics—insertion, update, and deletion anomalies that could lead to a loss of integrity.
1 NF:
A TABLE IS SAID TO BE IN 1n IF there is not repeating groups or information in a table..Here, repeating group means a set of columns that stores similar information that repeats in the same table.
Let’s consider following SQL commands.
Create table contacts
(
Contact Id Integer not null,
L_name varchar(20) not null,
F_name varchar(20)
Contact_date1 date,
Contact_desc1 varchar(50),
Contact_date2 date,
Contact_desc2 varchar(50),
);
We can see here in this table that there is a repeating group of date and description.
Now to convert into 1 N, we have to make a new table and shift that repeating group into new table.
Like,
Create table contacts
(
Contact_ID integer not null,
L_name varchar(20) not null,
F_name varchar(20)
);
Create table conversation
(
Contact_id integer not null,
Contact_date date,
Contact_desc varchar(50)
);
A table is said to be in 2 N if it is in 1N and there is no redundant data in table i.e. if a value of column is dependent on one column(primary key only) but not another.
For example:
Create table employee
(
Emp_no integer not null,
L-name varchar(20) not null,
F_name varchar(20),
Dept_code integer,
Description varchar(50),
);
This table contains redundant data i.e. the value of column(field) “description” depends on dept_code but does not depend on primary key “emp_no”.So let’s make a new table and shift them into that.
Create table employee
(
Emp_no integer not null,
L_name varchar(20) not null,
F_name varchar(20),
Dept_code integer,
);
Create table department
(
Dept_code integer not null,
Description varchar(50) not null,
);
We got two tables named employee and department with fields. Both the tables are related by primary key called dept_code. Now there is no redundancy and table is in 2N.
An entity is said to be in the third normal form when,
1) It satisfies the criteria to be in the second normal form.
2) There exists no transitive functional dependency. (Transitive functional dependency can be best explained with the relationship link between three tables. If table A is functionally dependent on B, and B is functionally dependent on C then C is transitively dependent on A and B).
Example:
Consider a table that shows the database of a bookstore. The table consists of details on Book id, Genre id, Book Genre and Price. The database is maintained to keep a record of all the books that are available or will be available in the bookstore. The table of data is given below.
Book id | Genre id | Book genre | price |
121 | 2 | fiction | 150 |
233 | 3 | travel | 100 |
432 | 4 | sports | 120 |
123 | 2 | fiction | 185 |
424 | 3 | travel | 140 |
The data in the table provides us with an idea of the books offered in the store. Also, we can deduce that BOOK id determines the GENRE id and the GENRE id determines the BOOK GENRE. Hence we can see that a transitive functional dependency has developed which makes certain that the table does not satisfy the third normal form.
Book id | Genre id | price |
121 | 2 | 150 |
233 | 3 | 100 |
432 | 4 | 120 |
123 | 2 | 185 |
424 | 3 | 140 |
table book
Genre id | Book genre |
2 | fiction |
3 | travel |
4 | sports |
table genre
After splitting the tables and regrouping the redundant content, we obtain two tables where all non-key attributes are fully functional dependent only on the primary key.
When all the column in a table describe and depend upon the primary key,the table is 3N.
q5.compare star and ring topology.[5]
Ans:-
With the help of following paragraphs, we can understand about ring and star topology.
star topology:
A star topology is designed with each node (file server, workstations, and peripherals) connected directly to a central network hub, switch, or concentrator (See fig. 2).Data on a star network passes through the hub, switch, or concentrator before continuing to its destination. The hub, switch, or concentrator manages and controls all functions of the network.
It also acts as a repeater for the data flow. This configuration is common with twisted pair cable; however, it can also be used with coaxial cable or fiber optic cable.
Fig. 2. Star topology
Advantages of a Star Topology
Easy to install and wire.
No disruptions to the network when connecting or removing devices.
Easy to detect faults and to remove parts.
Disadvantages of a Star Topology
Requires more cable length than a linear topology.
If the hub, switch, or concentrator fails, nodes attached are disabled.
- Reduced chances of data collision as each node release a data packet after receiving the token.
- Token passing makes ring topology perform better than bus topology under heavy traffic.
- No need of server to control connectivity among the nodes.10. Describe the wireless network system. List out deices and equipment necessary for Wi-Fi network. 3+2
q6.What is variable?List the major data types used in C program.[2+3]
Ans:-
Variable:-
A variable is a value that can change any time. It is a memory location used to store a data value. A variable name should be carefully chosen by the programmer so that its use is reflected in a useful way in the entire program. Any variable declared in a program should confirm to the following:They must always begin with a letter, although some systems permit underscore as the first character.
- White space is not allowed.
- A variable name should not be a keyword.
- It should not contain any special characters.
Examples of invalid variable names are:
123 (area) 6th % abc
Integers:- An integer can be a whole number but not a fractional number. It can accept any + ve or –ve number. It is very common type of data used by computer. When we add/subtract/divide/multiply, we get integer but if output is in fractional, the system just truncates that decimal part and returns only integer part. Like 1+2 yields 3. 3 divided by 2 yields 1. For this data type in some language, we use some suffix like % or word like ‘int’.
Floating part:- If we are going to write a program which includes some like fraction type of data then we use this data type. Like, 1.23, -.34.45 etc. the computers recognize the real numbers having fractions easily and processes accordingly. For float type of data, we use some words like ‘float’ and some where suffix like ! or #.
Character type:- Simply a letter or a number or space or any other symbol which we use in program is called character. A single character is placed in a single quote like ‘a’ or ‘,’ or ‘1’ etc. but, if we combine many characters then we put inside double quote like “computer”, it has 8 characters. For this type, we use reserved word like ‘char’ in C and some where it is not needed.
String type: A data type which contains many characters together and mostly put inside double quote (in most language) is called string. Like “computing” or “education” etc. for this, we use reserved word char with some index value. In C, we can write char name[20];. Here name is a string type of data and holds up to 20 characters.
This data type is used for exponential values and for more accuracy of digits.It's working range is more than others. so if we want to use long numbers of any type and high accuracy then...? for example,
double ab;
'ab' is a variable of double type. It can store exponential values (3x104). It ca n be written as 3e+4 or 3E+4. If power is in negative form then it can be in 3e-4 or 3E-4. It has one advantage over others that it can be used in place of others easily.
No comments:
Post a Comment