You are on page 1of 15

CS 16 : FUNDAMENTALS OF COMPUTING AND PROGRAMMING JANUARY 2009

Part : A 1. Differentiate between volatile and Non volatile memory? Volatile Memory The data is lost on reboot. Non-Volatile Memory Data is saved to a hard drive or flash drive, or it could be a hard coded chip. So its not lost on reboot. Example is ROM memory(Read-onlymemory) All data that stored in this type of memory will retain when you shutdown your computer.

2 3

Example is the RAM memory( Random-access-memory). You will lost all of your data when your electricity go out. When you shutdown your computer. Info that havenot saved is destroyed.

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 of content. 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

Digital Equipment Corporation - All-in-1 Draw a Flow chart to read two numbers, calculate the sum and print the result.

6.

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 twodimensional 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).

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 o o o o Input Processing Output Storing Controlling

The characteristics of computers are o o o o o o o Speed Accuracy Diligence Reliability Storage Capability Versatility 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 = 7 3*8^1 = 24 ------------+ 31 37 Octal = 31 decimal ------------(iii) 0.37 Convert the octal fraction 0.37 to decimal

3/8+7/64 = 0.484375 0.37 octal = 0.484375 decimal (iv) Convert the decimal number 1723.256 to hexadecimal

1723\16 = 11 = B 107\16 = 11 = B 6 .256*16 0.096*16 0.536*16 0.576*16 0.216*16 0.456*16 = 4.096 = 1.536 = 8.576 = 9.216 = 3.456 = 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 DBMS Presentation application Spreadsheet Image Editor Word Processor Desktop Publishing S/W System software OS Device Drivers System Utilities Language Translators

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

(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 user If 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:

Flow chart to find greatest of 3 numbers Start

Read A, B, C

Yes

Is A>B & A>C

No

Is B>C

No

Yes

Print A is greatest

Print B is greatest

Print C is greatest

Stop

(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 part Executable part } User-defined functions { Statements }

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 <stdio.h> /* 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<=100;i++) { if (i%2==0) printf(%d \t,i); } } /* Alternate implementation */ void main() { int i; printf(\n Even numbers from 1 to 100 are \n);

for(i=2;i<=100;i=i+2) printf(%d \t,i); } (b) With relevant examples discuss the following unformatted input/output statements i) getchar() This function reads character data from the standard input one character at a time. #include <stdio.h> Main() { Char ch[20]; Int c=0; Clrscr(); While((ch[c] = getchar())!=\n) C++; Ch[c] = \0; Printf(\n%s, ch); } ii) getc() This function reads a single character from an opened file and moves the file pointer. It returns EOF if end of file is reached #include <stdio.h> #include <process.h> #include <conio.h> Void main() { FILE *f; Char c; Clrscr (); f=fopen(list.txt, r); if (f==NULL) { Printf (\nCannot open file); Exit(1); } While ((c=getc (f)) !=EOF Printf (%c, c); fclose(f); } iii) gets() This function accepts any string through standard input until enter key is pressed

#include <stdio.h> Main(0 { Char ch[30]; clrscr();

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 <stdio.h> 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 <stdio.h> #include<conio.h> 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 <stdio.h> Main(0 { Char ch[30]; clrscr();

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<stdio.h> #include<conio.h> 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<stdio.h> #include<conio.h> 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,*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 follows Struct 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;

Now ptr points to a structure of the type book. The members of the structure can be accessed using the -> operator. #include <stdio.h> #include<conio.h> 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 <stdio.h> 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); }

You might also like