DATA STRUCTURES MCA 1.2.2



MCA 1.2.2 DATA STRUCTURES. (Model Paper)





First Question is Compulsory

Answer any four from the remaining

Answer all parts of any Question at one place.

Time: 3 Hrs.                                               Max. Marks: 70





1. a) What is the difference in function between BALR and USING instructions?

b) Explain Allocation. c) Define Macro Instruction.

d) Differentiate in between pass and phase. e) Define Linkage Editor.

f) Define Compiler. g) Explain the importance of LESA.

g) Differentiate in between simple RELOCATABLE and complex

RELOCATABLE address constants.

i) Differentiate in between open subroutine and closed subroutine.

j) Explain the importance of RLD cards.





2. a) Explain the role of Base Register.

b) Explain the role of Index Register.

c) Differentiate in between USING and DROP PSEUDO op codes.





3. a) Give the design of single pass assembler.

b) Can we write an ALP without using USING OP CODE? How?

what are the limitations.





4 .a) Give the design of single pass macro processor.

b) Explain the design of macro processor which can handle macro definitions

within macros.





5. a) Give the design part of Assembler corresponding to LTORG pseudo op code.

b) Give the design of Assembler corresponding to Extended MNEUMONICS. c)

Will the following divide 10 by 2? Justify.

L3,=f’ 10’

D2,=f’2’

ST3, 700





6. a) Give the design of absolute loader.

b) Explain about Direct Linking Loader.





7. a) Explain BSS loader.

b) At what point in time of each of the following loading schemes perform binding?

i. DLL, ii. BSS loader, iii. Dynamic binder.

iv. Dynamic linking loader, v. Overlay, vi. Editor





8. a) Explain Lexical Analysis in detail

b) Differentiate between TDP & BUP

Pointer (interdiction)

                                   One of those things beginners in C find difficult is the concept of pointers. If you want have a clear idea about  c pointers first of all you need to have clear idea about  C variables. Thus we start with a discussion of C variables.

techaravind  c pointers


                                   A variable in a program is something with a name, the value of which can vary. The way the compiler and linker handles this is that it assigns a specific block of memory within the computer to hold the value of that variable. The size of that block depends on the range over which the variable is allowed to vary. For example, on 32 bit PC's the size of an integer variable is 4 bytes. On older 16 bit PCs integers were 2 bytes.  In C the size of a variable type such as an integer need not be the same on all types of machines.  Further more there is more than one type of integer variable in C.  We have integers, long integers and short integers which you can read up on in any basic text on C.  Here we assumes the use of a 32 bit system with 4 byte integers.



If you want to know the size of the various types of integers on your system, running the following code will give you that information.



#include <stdio.h>



int main()

{

printf("size of a short is %d\n", sizeof(short));

printf("size of a int is %d\n", sizeof(int));

printf("size of a long is %d\n", sizeof(long));

}



When we declare a variable we inform the compiler of two things, the name of the variable and the type of the variable. For example, we declare a variable of type integer with the name k by writing:



    int k;



On seeing the "int" part of this statement the compiler sets aside 4 bytes of memory (on a PC) to hold the value of the integer. It also sets up a symbol table. In that table it adds the symbol k and the relative address in memory where those 4 bytes were set aside.



Thus, later if we write:



    k = 2;



we expect that, at run time when this statement is executed, the value 2 will be placed in that memory location reserved for the storage of the value of k. In C we refer to a variable such as the integer k as an "object".



In a sense there are two "values" associated with the object k. One is the value of the integer stored there (2 in the above example) and the other the "value" of the memory location, i.e., the address of k. Some texts refer to these two values with the nomenclature rvalue (right value, pronounced "are value") and lvalue (left value, pronounced "el value") respectively.



In some languages, the lvalue is the value permitted on the left side of the assignment operator '=' (i.e. the address where the result of evaluation of the right side ends up). The rvalue is that which is on the right side of the assignment statement, the 2 above. Rvalues cannot be used on the left side of the assignment statement. Thus: 2 = k; is illegal.



Actually, the above definition of "lvalue" is somewhat modified for C. According to K&R II (page 197): [1]



    "An object is a named region of storage; an lvalue is an expression referring to an object."



However, at this point, the definition originally cited above is sufficient. As we become more familiar with pointers we will go into more detail on this.



Okay, now consider:



   int j, k;



    k = 2;

    j = 7;    <-- line 1

    k = j;    <-- line 2



In the above, the compiler interprets the j in line 1 as the address of the variable j (its lvalue) and creates code to copy the value 7 to that address. In line 2, however, the j is interpreted as its rvalue (since it is on the right hand side of the assignment operator '='). That is, here the j refers to the value stored at the memory location set aside for j, in this case 7. So, the 7 is copied to the address designated by the lvalue of k.



In all of these examples, we are using 4 byte integers so all copying of rvalues from one storage location to the other is done by copying 4 bytes. Had we been using two byte integers, we would be copying 2 bytes.



Now, let's say that we have a reason for wanting a variable designed to hold an lvalue (an address). The size required to hold such a value depends on the system. On older desk top computers with 64K of memory total, the address of any point in memory can be contained in 2 bytes. Computers with more memory would require more bytes to hold an address.  The actual size required is not too important so long as we have a way of informing the compiler that what we want to store is an address.



Such a variable is called a pointer variable (for reasons which hopefully will become clearer a little later). In C when we define a pointer variable we do so by preceding its name with an asterisk. In C we also give our pointer a type which, in this case, refers to the type of data stored at the address we will be storing in our pointer. For example, consider the variable declaration:



   int *ptr;



ptr is the name of our variable (just as k was the name of our integer variable). The '*' informs the compiler that we want a pointer variable, i.e. to set aside however many bytes is required to store an address in memory. The int says that we intend to use our pointer variable to store the address of an integer. Such a pointer is said to "point to" an integer. However, note that when we wrote int k; we did not give k a value. If this definition is made outside of any function ANSI compliant compilers will initialize it to zero. Similarly, ptr has no value, that is we haven't stored an address in it in the above declaration. In this case, again if the declaration is outside of any function, it is initialized to a value guaranteed in such a way that it is guaranteed to not point to any C object or function. A pointer initialized in this manner is called a "null" pointer.



The actual bit pattern used for a null pointer may or may not evaluate to zero since it depends on the specific system on which the code is developed. To make the source code compatible between various compilers on various systems, a macro is used to represent a null pointer. That macro goes under the name NULL. Thus, setting the value of a pointer using the NULL macro, as with an assignment statement such as ptr = NULL, guarantees that the pointer has become a null pointer. Similarly, just as one can test for an integer value of zero, as in if(k == 0), we can test for a null pointer using if (ptr == NULL).



But, back to using our new variable ptr. Suppose now that we want to store in ptr the address of our integer variable k. To do this we use the unary & operator and write:



    ptr = &k;



What the & operator does is retrieve the lvalue (address) of k, even though k is on the right hand side of the assignment operator '=', and copies that to the contents of our pointer ptr. Now, ptr is said to "point to" k. Bear with us now, there is only one more operator we need to discuss.



The "dereferencing operator" is the asterisk and it is used as follows:



    *ptr = 7;



will copy 7 to the address pointed to by ptr. Thus if ptr "points to" (contains the address of) k, the above statement will set the value of k to 7. That is, when we use the '*' this way we are referring to the value of that which ptr is pointing to, not the value of the pointer itself.



Similarly, we could write:



 printf("%d\n",*ptr);



to print to the screen the integer value stored at the address pointed to by ptr;.



One way to see how all this stuff fits together would be to run the following program and then review the code and the output carefully.



------------ Program 1.1 ---------------------------------



/* Program 1.1 from PTRTUT10.TXT   6/10/97 */



#include <stdio.h>



int j, k;

int *ptr;



int main(void)

{

    j = 1;

    k = 2;

    ptr = &k;

    printf("\n");

    printf("j has the value %d and is stored at %p\n", j, (void *)&j);

    printf("k has the value %d and is stored at %p\n", k, (void *)&k);

    printf("ptr has the value %p and is stored at %p\n", ptr, (void *)&ptr);

    printf("The value of the integer pointed to by ptr is %d\n", *ptr);



    return 0;

}



Note: We have yet to discuss those aspects of C which require the use of the (void *) expression used here. For now, include it in your test code. We'll explain the reason behind this expression later.

Student Record-File Management Program in C

c-techaravind-student-record-img
                                              To compile and execute the program, copy the code into a text file. Save the text file with the extinction .c (ex. program.c). Save your file in turboc2 or borland (it may your othe c-compiler). Now open you IDE (tc.exe) , goto file->pick file. Your source file will be loaded into IDE. Now you can compile and run the file easily.

C program for append,list,search ,modify,delete a student record in a File.


#include<stdio.h>
#include<conio.h>
void append();
void list();
void search();
void modify();
void del();

struct student
{
int no;
char name[20];
};

void main()
{
int a;
char ch;
clrscr();
do{
printf("\nstudent DATABASE\n\n");
printf("1.Append student Record\n2.List student Record\n3.Modify student Record\n4.Delete student Record\n5.Search student Record\n Enter Choice : ");
scanf("%d",&a);
switch(a)
{
case 1:
append();
break;
case 2:
list();
break;
case 3:
modify();
break;
case 4:
del();
break;
case 5:
search();
break;
default :
printf("Invalid Choice!");
}
printf("\n More Actions ? (Y/N) :");
fflush(stdin);
scanf("%c", &ch);
}while(ch=='y'|| ch=='Y');
}

void append()
{
int i,n;
struct student e;
FILE *fp;
fp=fopen("student.dat", "a");
if(fp==NULL)
{
printf("File Creation Failed!");
exit(0);
}
printf("Enter the nos. of students : ");
scanf("%d", &n);
for(i=0;i<n;i++)
{
printf("Enter the student Number : ");
scanf("%d", &e.no);
printf("Enter the student Name : ");
fflush(stdin);
gets(e.name);
printf("\n\n");
fwrite((char *)&e, sizeof(e), 1, fp);
}
fclose(fp);
}

void list()
{
int nofrec=0;
struct student e;
FILE *fp;
fp=fopen("student.dat", "rb");
if(fp==NULL)
{
printf("\n\tFile doesn’t exist!!!\TRY AGAIN");
exit(0);
}
while((fread((char *)&e, sizeof(e), 1, fp))==1)
{
nofrec++;
printf("\nstudent Number : %d", e.no);
printf("\nstudent Name : %s",e.name);
printf("\n\n");
}
printf("Total number of records present are : %d", nofrec);
fclose(fp);
}

void modify()
{
int recno, nofrec=0;
char ch;
struct student e;
FILE *fp;
fp=fopen("student.dat", "rb+");
printf("Enter the student Number to modify : ");
scanf("%d", &recno);
while((fread((char *)&e, sizeof(e), 1, fp))==1)
{
nofrec++;
if(e.no==recno)
{
printf("\nstudent Number : %d", e.no);
printf("\nstudent Name : %s",e.name);
printf("\n");
printf("Do you want to modify this record : ? (Y/N)");
fflush(stdin);
scanf("%c", &ch);
fseek(fp, ((nofrec-1)*sizeof(e)), 0);
if(ch=='Y'|| ch=='y')
{
printf("Enter the student No : ");
scanf("%d",&e.no);
printf("Enter the student Name : ");
fflush(stdin);
gets(e.name);
fwrite((char *)&e, sizeof(e), 1, fp);
printf("Record Modified");
}
else
printf("No modifications were made");
fclose(fp);
}
}
}
void del()
{
int recno;
char ch;
struct student e;
FILE *fp, *ft;
fp=fopen("student.dat", "rb");
ft=fopen("Temp.dat", "wb");
printf("Enter the student Number to delete : ");
scanf("%d", &recno);
while((fread((char *)&e, sizeof(e), 1, fp))==1)
{
if(e.no==recno)
{
printf("\nstudent Number : %d", e.no);
printf("\nstudent Name : %s",e.name);
printf("\n");
printf("Do you want to delete this record : ? (Y/N)");
fflush(stdin);
scanf("%c", &ch);
}
}
if(ch=='y'||ch=='Y')
{
rewind(fp);
while((fread((char *)&e, sizeof(e), 1, fp))==1)
{
if(recno!=e.no)
{
fwrite((char *)&e, sizeof(e), 1, ft);
}
}
}
else
printf("No Record was deleted");
fclose(fp);
fclose(ft);
remove("student.dat");
rename("Temp.dat", "student.dat");
}


void search()
{
int s,recno;
char sname[20];
struct student e;
FILE *fp;
fp=fopen("student.dat", "rb");
printf("\n1.Search by Name\n2.Search by student No.\n Enter choice : ");
scanf("%d", &s);
switch(s)
{
case 1:
printf("Enter the student Name to Search : ");
fflush(stdin);
gets(sname);
while((fread((char *)&e, sizeof(e), 1, fp))==1)
{
if(strcmp(sname,e.name)==0)
{
printf("\nstudent Number : %d", e.no);
printf("\nstudent Name : %s",e.name);
printf("\n");
}
}
break;
case 2:
printf("Enter the student Number to Search : ");
scanf("%d", &recno);
while((fread((char *)&e, sizeof(e), 1, fp))==1)
{
if(e.no==recno)
{
printf("\nstudent Number : %d", e.no);
printf("\nstudent Name : %s",e.name);
printf("\n");
}
}
break;
}
}




Roots of a given quadratic equation in C

c-techaravind


                                              To compile and execute the program, copy the code into a text file. Save the text file with the extinction .c (ex. program.c). Save your file in turboc2 or borland (it may your othe c-compiler). Now open you IDE (tc.exe) , goto file->pick file. Your source file will be loaded into IDE. Now you can compile and run the file easily.







#include<stdio.h>
#include<math.h>
void main()
{
int A, B, C;
float disc, x1, x2;
clrscr();
gotoxy(31,1);
printf("Root of a quadratic equation");
gotoxy(26,3);
printf("http:\\techaravind.blogsopt.com");
gotoxy(1,5);

printf("\n\n\t ENTER THE VALUES OF A,B,C...");
scanf("%d,%d,%d", &A, &B, &C);
disc=(B * B) - (4 * A * C);
if(disc > 0)
{
printf("\n\t THE ROOTS ARE REAL ROOTS");
x1 = (-B/2 * A) + (sqrt((B * B) - (4 * A * C)) /2 * A);
x2 = (-B/2 * A) - (sqrt((B * B) - (4 * A * C)) / 2 * A);
printf("\n\n\t THE ROOTS ARE...: %f and %f\n", x1, x2);
}
else if(disc == 0)
{
printf("\n\t THE ROOTS ARE REPEATED ROOTS");
x1 = -B/2 * A;
printf("\n\n\t THE ROOT IS...: %f\n", x1);
}
else
printf("\n\t THE ROOTS ARE IMAGINARY ROOTS\n");
getch();
}

 
Etutos © 2010-2011