cs 16-jan 2009

Upload: chengathirselvi

Post on 07-Apr-2018

222 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/6/2019 CS 16-Jan 2009

    1/15

  • 8/6/2019 CS 16-Jan 2009

    2/15

  • 8/6/2019 CS 16-Jan 2009

    3/15

  • 8/6/2019 CS 16-Jan 2009

    4/15

    CS 16 : FUNDAMENTALS OF COMPUTING AND PROGRAMMING

    JANUARY 2009

    Part : A

    1. Differentiate between volatile and Non volatile memory?

    Volatile Memory Non-Volatile Memory

    1 The data is lost on reboot. Data is saved to a hard drive or flash drive, or

    it could be a hard coded chip. So its not lost

    on reboot.

    2 Example is the RAM memory(

    Random-access-memory).

    Example is ROM memory(Read-only-

    memory)

    3 You will lost all of your data when

    your electricity go out. When you

    shutdown your computer. Info that

    havenot saved is destroyed.

    All data that stored in this type of memory

    will retain when you shutdown your

    computer.

    2. Convert the Binary number (100111)2 to Decimal number.

    39

    3. What is a Web Browser? give example.

    A web browser is a software application for retrieving, presenting, and traversing

    information resources on the World Wide Web. An information resource is identified by a

    Uniform Resource Identifier (URI) and may be a web page, image, video, or other piece ofcontent.

    The major web browsers are Windows Internet Explorer, Mozilla Firefox, Apple Safari,

    Google Chrome, and Opera.

    4. Define an Operating System. Give example.

    An operating system (commonly abbreviated to either OS or O/S) is an interface

    between hardware and user.

    Common operating systems are Windows XP, Windows Vista, Windows NT, Mac OS,

    Linux and SunOS (Solaris/OpenSolaris).

    5. List any two commonly used Office Automation Software.

    Office Automation Software is a class of software used for creating a "Paperless

    Office" and allow groups of workers to share documents and files electronically. Typical

    packages included a word processing package, file storage, and calendar. Packages were

    available from a number of companies including:

    IBM - PROFS

  • 8/6/2019 CS 16-Jan 2009

    5/15

    Digital Equipment Corporation - All-in-1

    6. Draw a Flow chart to read two numbers, calculate the sum and print the result.

    7. What is a Data Type? Give example.

    A data type in programming languages is a set of values and the operations on those

    values. Common data types are:

    integers,

    floating-point numbers (decimals), and

    alphanumeric strings.

    8. What is Scope of a variable? List the two types of Scopes of a Variable in C

    language?

    The area or block of the C program from where the variable can be accessed is known

    as the scope of variable. The area or scope of the variable depends on the storage class, ie.how it is declared. The two types of scopes of a variable in C language are local variable and

    global variable.

    9. Define an array. Give example.

    An array is a collection of similar data types in which each element is located in

    separate memory locations.

    Example for an array is a Table implemented in system. A Table is declared as a two-

    dimensional array of some fixed-point decimal elements. The two dimensions of Table have

    bounds.

    10. State the purpose of preprocessor section in a C program.

    The preprocessor handles directives for source file inclusion (#include), macro

    definitions (#define), and conditional inclusion (#if).

  • 8/6/2019 CS 16-Jan 2009

    6/15

    Part B

    11 (a) (i) List and discuss the basic operations of a computer.

    (ii) Compare a computer with a Human being.

    (iii) List the characteristics of Computers.

    The basic operations of a computer are

    o Input

    o Processing

    o Output

    o Storing

    o Controlling

    The characteristics of computers are

    o Speed

    o Accuracy

    o Diligenceo Reliability

    o Storage Capability

    o Versatility

    o Resource Sharing

    Computers are used to perform intricate operations since they can process data at an

    extremely fast rate millions of instructions per second. In few seconds, a computer can

    perform a huge task that normal human beings may take days or even years to complete.

    Being a machine, it does not suffer from the traits of tiredness and concentration.

    11 (b) (i) Convert (0.39)10 to Octal

    0.39 * 8 = 3.12

    .12 * 8 = 0.96

    0.96 * 8 = 7.68

    0.68 * 8 = 5.44

    0.44 * 8 = 3.52

    0.52*8 = 4.16

    0.39 decimal = 0.307534 octal

    (ii) Convert the octal number 37 to decimal

    7*8^0 = 73*8^1 = 24

    -------------

    + 31 37 Octal = 31 decimal

    -------------

    (iii) Convert the octal fraction 0.37 to decimal

    0.37

  • 8/6/2019 CS 16-Jan 2009

    7/15

    3/8+7/64 = 0.484375

    0.37 octal = 0.484375 decimal

    (iv) Convert the decimal number 1723.256 to hexadecimal

    1723\16 = 11 = B107\16 = 11 = B

    6

    .256*16 = 4.096

    0.096*16 = 1.536

    0.536*16 = 8.576

    0.576*16 = 9.216

    0.216*16 = 3.456

    0.456*16 = 7.296

    1723.256 in decimal = 6BB.418937 in hexadecimal

    v) Convert the decimal number 39 to hexadecimal

    39\16 = 7

    2

    39 in decimal = 27 hexadecimal

    12 (a) With a tree diagram classify and discuss the different types of software

    Software

    Application Software System software

    DBMS Presentation application OS Device Drivers System Utilities

    Spreadsheet Image Editor Language Translators

    Word Processor Desktop Publishing S/W

    Software can be broadly categorized into Application software & System software.

    System Software

    -OS

    - Device drivers

    - System Utilities

    - Language Translators

    Application Software

    - DBMS

    - Presentation application

    - Spreadsheet

    - Image Editor

    - Word Processor

    - Desktop publishing software

  • 8/6/2019 CS 16-Jan 2009

    8/15

    (b) Illustrate and develop the different phases of software development cycle

    The various phases are

    - Problem analysis

    - Task analysis

    - Designing

    - Testing algorithm for accuracy

    - Coding

    - Testing and Debugging the program

    - Documentation and Implementation

    13(a) (i)Develop an algorithm to find the greatest of three numbers

    Step 1: Start

    Step 2: Get 3 numbers A,B,C as input from the user

    Step 3: Check if A is greater than B and also greater than C

    Step 4: If so print that A is the greatest and go to step 7

    Step 5: Check if B is greater than C

    Step 6: If yes print B is the greatest else print C is the greatest

    Step 7: End

    (ii)Develop a flowchart to find greatest of three numbers

    Figure in next page.

    (b) i) What is pseudo code? Develop pseudo code to check and print whether a given number

    is prime or not.

    Pseudocode is an outline of a program written in a form that can be easily converted into real

    programming statements. Pseudocode uses plain English statements in a structured way

    rather than symbols to represent the processes of a computer program.

    Start:

    Read a number N from the userIf N is equal to 2 display that it is prime and go to End

    Initialize a loop counter I as 2

    Loop:

    Increment I till N-1

    Determine if the remainder of N divided by I is 0

    If so print N is not prime and go to End else go to Loop

    Print N is prime

    End:

  • 8/6/2019 CS 16-Jan 2009

    9/15

    Flow chart to find greatest of 3 numbers

    (ii) Highlight the features of spreadsheets

    Refer June 2007 13(b) (i)

    14 (a)

    i) Explain the structure of a C program

    A C program comprises of the following sections

    Include header file section

    Global declaration section

    /* comments */

    main () /* function name */

    {

    /* comments */

    Declaration partExecutable part

    }

    User-defined functions

    {

    Statements

    }

    Read A,

    B, C

    Is A>B&

    A > C

    Is

    B>C

    Print A is

    greatest Print B isgreatest

    Print C is

    greatest

    Stop

    Start

    Yes

    Yes

    NoNo

  • 8/6/2019 CS 16-Jan 2009

    10/15

    Include header file section:

    All header files that contain function definitions that are used in the program should

    be listed in this section using the #include directive

    Global declaration

    This section declares global variables that are used in multiple functions.

    Function main

    The function main() is the starting point of every C program. Program execution starts

    with the opening brace and ends with the closing brace.

    Declaration part

    This section is used to declare the entire variables that are used in executable part.

    Initialization of variables is also done in this section.

    Executable part

    This part contains a set of statements or a single statement that perform some

    processing logic.

    User defined function

    Functions added by the user are called user defined functions

    Comments

    Comments can be placed anywhere in a program and are enclosed within the

    delimiters /* and */. Comments are not executed by the complier but they are useful to

    improve the clarity of the program and for documentation.

    ii) Develop a C program to print the even numbers between 1 & 100

    # include

    /* program to print even numbers from 1 to 100 */

    void main()

    {

    int i;

    printf(\n Even numbers from 1 to 100 are \n);

    for (i=2;i

  • 8/6/2019 CS 16-Jan 2009

    11/15

    for(i=2;i

  • 8/6/2019 CS 16-Jan 2009

    12/15

    printf(enter the string : );

    gets(ch);

    printf(\nentered string: %s, ch);

    }

    iv) putchar()

    This function prints one character on the screen at a time which is read by the

    standard input

    #include

    Main(0

    {

    Char ch[20];

    Int c=0;

    clrscr();

    printf(Enter Text here : );

    scanf(%s, ch);

    printf(\n The entered text : );

    while (ch[c]!=\0){

    Putchar (ch[c]);

    C++;

    }

    }

    v) putc()

    This functions writes a single character to a file. If an error occurs it returns EOF

    #include

    #include

    Main(0

    {

    Int c;

    FILE *fp;

    clrscr();

    printf(\n Enter Few Words * to Exit \n);

    fp=fopen (words.doc, w);

    while ((c=getchar()) != *);

    putc(c,fp);

    fclose(fp);

    }

    vi)puts()

    This function prints the string or character array.

    #include

    Main(0

    {

    Char ch[30];

    clrscr();

  • 8/6/2019 CS 16-Jan 2009

    13/15

    printf(enter the string : );

    gets(ch);

    puts(\nEntered string: %s, ch);

    puts(ch);

    }

    15 (a) With relevant examples discuss the following

    i) Call by value

    In this type value of actual arguments are passed to the formal arguments and the

    operation is done on formal arguments. Any change made in the formal arguments does not

    affect the actual arguments because formal arguments are photocopies of actual arguments.

    Changes made in the formal arguments are local to the block of the called function.

    # include

    #include

    main()

    {

    Int x, y, change (int, int);Clrscr();

    printf(\n Enter values of x & y :);

    scanf (%d %d, &x, &y);

    change(x,y);

    printf (\n In main() x=%d y=%d, x,y);

    return 0;

    }

    Change (int a, int b)

    {

    Int k;

    k=a;

    a=b;

    b=k;

    printf(\n In change () x=%d y=%d, a,b);

    }

    ii) Call by reference

    In this type instead of passing values, addresses are passed. The function operates on

    addresses rather than values. Since he formal arguments point to the actual argument any

    changes made in the arguments are permanent.

    # include#include

    main()

    {

    int x,y,change(int *,int *);

    clrscr();

    printf(\n Enter values of x & y :);

    scanf(%d %d,&x,&y);

    change(&x,&y);

  • 8/6/2019 CS 16-Jan 2009

    14/15

    printf(\n In main x=%d y=%d,*a,*b);

    return 0;

    }

    change(int *a,int *b)

    {

    int *k;

    *k=*a;*a=*b;

    *b=*k;

    printf(\n In change x=%d y=%d,*a,*b);

    }

    (b) With relevant examples discuss structures and unions in C

    Structures:

    A structure is a collection of one or more variables of different data types grouped together

    under a single name.

    A structure can be declared as followsStruct struct_type

    {

    type variable1;

    type variable2;

    };

    After defining a structure we can define variables as follows

    struct struct_type v1,v2,v3;

    Memory allocation takes place only when variables are declared.

    (Eg) struct book1

    {

    char book[30];

    int pages;

    float price;

    };

    struct book1 bk1;

    The above line creates a variable bk1 of type book1. The dot operator is used to access the

    structure members

    We can use the objects of one structure as members in another structure and we can also

    define an array of structures.

    We can also use a pointer to refer to a structure as follows

    struct book

    {

    char name[25];

    char author[25];

    int pages;

    };

    struct book *ptr;

  • 8/6/2019 CS 16-Jan 2009

    15/15

    Now ptr points to a structure of the type book. The members of the structure can be accessed

    using the -> operator.

    #include

    #include

    main(){

    struct book

    {

    char name[25];

    char author[25];

    int pages;

    };

    Struct book b1={JAVA COMPLETE REFERENCE, P NAUGHTON, 886};

    struct book *ptr;

    ptr = &b1;

    clrscr();

    printf(\n %s by %s of %d pages, b1.name, b1.author, b1.pages);printf(\n %s by %s of %d pages, ptr-> name, ptr->author, ptr->pages);

    }

    Union

    Union is a variable which contains a number of members like structure but it only holds one

    object at a time. In a structure each member has its own memory location whereas members

    of unions share the same memory location.

    A union requires bytes that are equal to the size of the largest member. A union can only

    accommodate one member at a time in a single area of storage.

    #include

    Main()

    {

    Union result

    {

    Int marks;

    Char grade;

    };

    struct res

    {

    Char name [15];Int age;

    union result perf;

    } data;

    clrscr();

    printf(size of union: %d\n, sizeof (data.perf));

    printf(size of structure: %d\n, sizeof (data));

    printf(\nentered string: %s, ch);

    }