How To Exam?

a knowledge trading engine...


Indira Gandhi National TribalUniversity, Amarkantak 2011 M.C.A Problem Solving and Programming (Assignment) - Question Paper

Friday, 01 February 2013 05:35Web


Course Code : MCS-011
Course Title : issue Solving and Programming
Q1: (a) Write a simple program to obtain the size of various basic data kinds in C.
Hint: Program to obtain the size of various basic data kinds in C
#include
#include
void main()
{
int x;
float y;
char z;
double d;
long l;
clrscr();
printf("size of integer= %d",sizeof(x));
printf("\nsize of float= %d",sizeof(y));
printf("\nsize of char= %d",sizeof(z));
printf("\nsize of double= %d",sizeof(d));
printf("\nsize of long= %d",sizeof(l));
getch();
}
(b) Write a program in C for arithmetic operations ranging from 2 integers. Your program should guide users with proper message/menu on the console.
Hint: program in c for arithmetic operations ranging from 2 integers. your program should guide users withproper message/menu on the console.
#include
#include
void main()
{
int num1,num2,sum,difference,mul,choice;
float div;
begin :
clrscr();
printf("\n1.addition");
printf("\n2.subtraction");
printf("\n3.multiplication");
printf("\n4.division");
printf("\n5.exit.");
printf("\n\nenter your choice:");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("\nenter 1st number");
scanf("%d",&num1);
printf("\nenter 2nd number");
scanf("%d",&num2);
printf("\n sum of 2 numbers=%d",(num1+num2));
break;
case 2:
printf("\nenter 1st number");
scanf("%d",&num1);
printf("\nenter 2nd number");
scanf("%d",&num2);
printf("\n difference of 2 numbers=%d",(num1-num2));
break;
case 3:
printf("\nenter 1st number");
scanf("%d",&num1);
printf("\nenter 2nd number");
scanf("%d",&num2);
printf("\n product of 2 numbers=%d",(num1*num2));
break;
case 4:
printf("\nenter 1st number");
scanf("%d",&num1);
printf("\nenter 2nd number");
scanf("%d",&num2);
printf("\n division of 2 numbers=%d",(num1/num2));
break;
case 5:
printf("\npress enter to exit");
getch();
exit(0);
default :
printf("\nyou have entered wrong choice:\n please enter new choice:");
goto start;
}
}
(c) Write a function Pali(Sting S) to obtain whether S is palindrome or not.
Hint: function pali (sting s) to obtain whether s is palindrome or not.
pali (char s[])
{
int length,i,j,flag=0;
length=strlen(s);
for(i=0,j=length-1;i<(length/2),j>(length/2);i++,j--)
{
if(s[i]!=s[j])
flag=1;
}
if(flag==1)
{
printf("\nstring is not pallendrome");
}
else
{
printf("\nstring is pallendrome");
}
getch();
}
Q2: (a) Write a C program to print this triangle:
*
***
*****
*******
*********
************
Hint:
#include
#include
void main()
{
int i,j;
for(i=0;i<12;i+=2)
{
for(j=i;j>=0;j--)
{
printf("*");
}
printf("\n");
}
getch();
}
(b) Write a C program to calculate the avg. marks in a subject of all the students in a class.
Hint: C program to calculate the avg. marks in a subject of all the students in a class.
#include
#include
void main()
{
int marks, i, noofstudents, sum=0;
float avg;
clrscr();
printf("enter no of students");
scanf("%d",&noofstudents);
printf(„\n enter marks of students");
for(i=0;i{
scanf("%d",&marks);
sum+=marks;
}
printf("\naverage of class=%f",(sum/noofstudents));
getch();
}
Q3 (a)Write a program to get the value of sin (x) using a library function , when x is provided in degrees.
Hint: #include #include
#include
void main() { float x,value; printf("\n Enter a number to get its Sin(x) value="); scanf("%f",&x); clrscr(); value=sin(x); printf("\n Value of Sin(x)=%f",value); getch(); }
(b) There are 20 integer values stored in an array. Write a programme to obtain largest and smallest value store.
Hint: There are 20 integer values stored in an array. Write a programme to obtain larges and smallest value store.
#include
#include
void main()
{
int num[20],largest,smallest,i;
clrscr();
printf("\nenter twenty numbers");
for(i=0;i<20;i++)
{
scanf("%d",&num[i])
}
largest=num[0];
smallest=num[0];
for(i=1;i<20;i++)
{
if(num[i]>largest)
largest=num[i];
if(num[i]smallest=num[i];
}
printf("\nsmallest of 20 numbers=%d",smallest);
printf("\nlargest of 20 numbers=%d",largest);
getch();
}
( c)Write a c program for binary addition of 2 eight bit numbers.
Hint:
# include
# include
# include
void binaryadd(int,int*,int*,int); /* funtion to add to binay numbers */
int a[8],b[8],c[8]; /* as we want eight bits , here extern data kind is needed */
void main()
{ clrscr();
int n1,n2,i=0,carry=0,*m,*n,k,x,y,d[8]={1,0,0,0,0,0,0,0};
char op;
gotoxy(1,6);printf("Enter first Numbers :");
scanf("%d",&n1);
gotoxy(1,7);printf("Enter second Numbers :");
scanf("%d",&n2);
oper: /* tag to return back if user provide wrong operator */
gotoxy(1,11);printf(" ");
gotoxy(1,8);printf("\nEnter the operator(+,-) :");
op=getch();
x=n1; /* for future refence in case of substraction */
y=n2;
if(op =='+' || op=='-')
{ while(n1!=0) /* converting first number to its binary equivalent */
{ a[i]=n1 % 2;
n1/=2;
i++;
}
/* printing first number */
printf("\nThe binary of %d is : ",x);
for(k=7;k>=0;k--)
printf("%d",a[k]);
printf("\n");
i=0;
while(n2!=0)
{ b[i]=n2 % 2; /* converting second number to its binary equivalent */
n2/=2;
i++;
}
/* printing binary of second number */
printf("\nThe binary of %d number is :",y);
for(k=7;k>=0;k--)
printf("%d",b[k]);
printf("\n");
}
switch(op)
{ case '+':
i=0;
m=a;
n=b;
carry=0;
binaryadd(i,m,n,carry); /*function called for binary add */
printf("\nThe addition is :");
for(i=7;i>=0;i--)
{ printf("%d",c[i]);
}
break;
case '-':
for(i=0;i<=7;i++)
{ if(b[i]==0)
b[i]=1; /* 1's complement */
else
b[i]=0;
}
printf("\nThe 1's complement of %d is : ",y);
for(i=7;i>=0;i--)
printf("%d",b[i]);
i=0;
m=b;
n=d;
carry=0;
binaryadd(i,m,n,carry); /* called for 2's complement */
printf("\nThe 2's complement of %d is : ",y);
for(i=7;i>=0;i--)
printf("%d",c[i]);
for(i=0;i<=7;i++)
b[i]=c[i];
i=0;
m=a;
n=b;
carry=0;
binaryadd(i,m,n,carry);
if(x>y)
{ printf("\nThe substaction is : ");
for(i=7;i>=0;i--)
printf("%d",c[i]);
if(x < y)
{ for(i=7;i>=0;i--)
{ if(c[i]==0)
c[i]=1;
else
c[i]=0;
}
i=0;
m=c;
n=d;
carry=0;
binaryadd(i,m,n,carry);/* again 2's complement for negative answers */
printf("\nThe subsraction is : ");
printf("-");
for(i=7;i>=0;i--)
printf("%d",c[i]);
}
exit(0);
break;
default:
gotoxy(1,11);printf("WRONG OPTION");
getch();
goto oper;
}
getch();
}
void binaryadd(int i,int *m,int *n,int carry)
{ if(*m==1 && *n==1 && carry==1)
{ c[i]=1;
carry=1;
}
if(*m==1 && *n==1 && carry==0)
{ c[i]=0;
carry=1;
}
if(*m==0 && *n==1 && carry==0)
{ c[i]=1;
carry=0;
}
if(*m==0 && *n==1 && carry==1)
{ c[i]=0;
carry=1;
}
if(*m==1 && *n==0 && carry==0)
{ c[i]=1;
carry=0;
}
if(*m==1 && *n==0 && carry==1)
{ c[i]=0;
carry=1;
}
if(*m==0 && *n==0 && carry==0)
{ c[i]=0;
carry=0;
}
if(*m==0 && *n==0 && carry==1)
{ c[i]=1;
carry=0;
}
i++;
m++;
n++;
if(i<=8) /* Base value of recursion */
binaryadd(i,m,n,carry); /* recursion till we reach eight bit of number */
}
Q4: (a) Using Pointers,
i) Write the character-counting function
Hint:
int CharCount(char *str) { int count = 0; if (str != NULL) { for (; *(str + count) != ''; ++count);
} return count; }
ii) Write the string-concatenation program
Hint: string_concatenate(char *s1,char *s2) { int i,j; char s3[50]; for(i=0;i s3[i]=s1[i]; for(j=0;j s3[i+j]=s2[j]; s3[i+j]=s2[j]; printf("%s",s3); }
(b) discuss pointer arithmetic with example. Also discuss advantages of malloc and calloc
Hint: A pointer is a variable that contains the memory location of a different variable. The syntax is as shown beneath. You begin by specifying the kind of data stored in the location identified by the pointer. The asterisk tells the compiler that you are creating a pointer variable. Finally you provide the name of thevariable.
kind * variable name Example:
int *ptr; float *string;
C allows us to add integers to or subtract integers from pointers as well as to subtract 1 pointer from the other. We can also use short hand operators with the pointers p1+=; sum+=*p2; etc.,
we can also compare pointers by using relational operators the expressions such as p1 >p2 , p1==p2 and p1!=p2 are allowed. /*Program to illustrate the pointer expression and pointer arithmetic*/ #include< stdio.h > main() { int ptr1,ptr2; int a,b,x,y,z; a=30;b=6; ptr1=&a; ptr2=&b; x=*ptr1+ *ptr2 –6; y=6*- *ptr1/ *ptr2 +30; printf("\nAddress of a +%u",ptr1); printf("\nAddress of b %u",ptr2); printf("\na=%d, b=%d",a,b); printf("\nx=%d,y=%d",x,y); ptr1=ptr1 + 70; ptr2= ptr2; printf("\na=%d, b=%d",a,b); }.
Advantage of Malloc and Calloc
malloc() allocates byte of memory, whereas calloc()allocates block of memory.
Calloc(m, n) is essentially equivalent to p = m*malloc(n); memset(p, 0, m * n); The zero fill is all-bits-zero, and does not therefore guarantee useful null pointer values (see part five of this list) or floating-point zero values. Free is properly used to free the memory allocated by calloc.
Malloc(s); returns a pointer for enough storage for an object of s bytes. Calloc(n,s); returns a pointer for enough contiguous storage for n objects, every of s bytes. The storage is all initialized to zeros.
Simply, malloc takes a single argument and allocates bytes of memory as per the argument taken during its invocation. Where as calloc takes 2 aguments, they are the number of variables to be created and the capacity of every vaiable (i.e. the bytes per variable).
Q5: (a) Write a C program for Tower of Hanoi issue with a example of four disks
Hint: #include
#include
void main()
{
void hanoi(char,char,char,int);
char t1='A',t2='B',t3='C';
int n;
clrscr();
printf("\n Enter the no. of disks on Tower A:");
scanf("%d",&n);
if(n<1)
{
printf("\n Nothing to move");
}
else
hanoi(t1,t2,t3,n);
getch();
}
void hanoi(char t1,char t2,char t3,int n)
{
static int step=0;
step++;
printf("\n %c %c %c %d",t1,t2,t3,n);
if(n==1)
{
printf("\n Move top disk from Tower %c ----> %c",t1,t2);
return;
}
hanoi(t1,t3,t2,n-1);
printf("\n %c %c %c %d",t1,t2,t3,n);
printf("\n Move top disk from Tower %c ----> %c",t1,t2);
printf("\n %c %c %c %d",t1,t2,t3,n);
hanoi(t3,t2,t1,n-1);
printf("\n %c %c %c %d steps=%d",t1,t2,t3,n,step);
}
(b) Write a C program to store students records in a file.
Hint: #include
#include
#include
const int MAX_CLASS_SIZE = 500;
const int MAX_SURNAME_SIZE = 20;
const int MAX_FNAME_SIZE = 40;
struct learner {
char id[10];
char surname[MAX_SURNAME_SIZE];
char firstname[MAX_FNAME_SIZE];
};
typedef learner StudentGroup[];
void getStudent(Student& s);
void displayStudent(Student s);
void getData(StudentGroup arr, int& howMany);
void bubSort(StudentGroup arr, int howMany);
void displayReport(StudentGroup arr, int howMany);
void main()
{
learner s[MAX_CLASS_SIZE];
int n = 0;
getData(s,n);
bubSort(s,n);
displayReport(s,n);
}
void getStudent(Student& s)
{
Scanf("%s", s.id);
Scanf("%s", s.surname);
getline(s.firstname, MAX_FNAME_SIZE); // collects rest of input line
}
void displayStudent(Student s)
{
Printf("%s %s %s", s.id , s.firstname,s.surname);
// this was screwed up because I had ' ' instead of " "
}
void getData(StudentGroup arr, int& howMany)
{
howMany = 0;
while (1)
{
getStudent(arr[howMany]);
if(cin) // successful data learn of one learner
{
howMany++;
}
}
}
void bubSort(StudentGroup arr, int n)
{
}
void displayReport(StudentGroup arr, int howMany)
{
for (int i=0; i{
displayStudent(arr[i]);
}
Printf( "Finshed writing report\n");
}



IGNOU MCA MCSL-17 Solved Assignment 2011

 

Course Code : MCSL-017

Course Title : C and Assembly Language Programming

Assignment Number : MCA(1)/L017/Assign/2011

Maximum Marks : 100

Weightage : 25%

Last Dates for Submission : 30th April, 2011 (For January Session)

31st October, 2011 (For July Session)

 

This assignment has two sections. Answer all questions in each section. Each Section is of 20 marks. Your Lab Records will carry 40 Marks. Rest 20 marks are for viva voce. You may use illustrations and diagrams to enhance the explanations. Please go through the guidelines regarding assignments given in the programme guide for the format of presentation.

 

Section 1: C Programming Lab

 

Question 1:

 

Write an interactive program in C language to manage the Clinic Information with menu options like Patients details, Doctors details, Doctors and Patients visits, Laboratory details, Bills, Payments etc. using the file handling concepts. The application should be designed user-friendly. (20 Marks)

 

Note: You must execute the program and submit the program logic, sample input and output along with the necessary documentation for this question. Assumptions can be made wherever necessary.

 

Solution:
 
#include<stdio.h>

#include<conio.h>

#include<string.h>

#define MAX 25

 

void inputDoctor(int);

void insertDoctor();

int searchDoctor(int);

void delDoctor();

void displayDoctor();

 

void inputPatient(int);

void insertPatient();

int searchPatient(int);

void delPatient();

void displayPatient();

 

void inputDocPatVisit(int);

void insertDocPatVisit();

int searchDocPatVisit(int);

void delDocPatVisit();

void displayDocPatVisit();

 

struct doctor

{

int docCode;

char name[20];

char address[100];

char splIn[30];

};

 

struct doctor doc[MAX];

 

struct patient

{

int patientCode;

char name[20];

char address[100];

char dis[30];

};

struct patient patient[MAX];

 

struct DocPatVisit

{

int docCode;

int patCode;

char DatOfVisit[10];

char Remark[100];

};

struct DocPatVisit DocPat[MAX];

 

 

int nDoc,recSizeDoc; /*Total number of elements in the list of Doctor and Recrd Siz */

int nPat,recSizePat; /*Total number of elements in the list of Patients and Recrd Siz */

int nDocPat,recSizeDocPat; /*Total number of elements in the list of Doctor Patients Visit and Recrd Siz */

 

FILE *fpDoc , *fpPat , *fpDocPat ;

 

void main()

{

int i=0,choice,pos,check,iptime=0;

int ldocCode,lpatientCode,lDocPatVisitCode;

 

int isRun1=1 ,isRun2=1;

////////////////////////////////////////////////////////////////////////////

 

fpDoc = fopen("DOC.dat","rb+");

 

if(fpDoc==NULL)

{

fpDoc = fopen("DOC.dat","wb+");

if(fpDoc == NULL)

{

puts("Can not open Source File");

getch();

exit(1);

}

}

 

recSizeDoc = sizeof(struct doctor);

 

////////////////////////////////////////////////////////////////////////

i=0;

 

rewind(fpDoc);

while(fread(&doc[i],recSizeDoc,1,fpDoc)==1)

{ i++; }

nDoc=i;

//////////////////////////////////

 

 

////////////////////////////////////////////////////////////////////////

fpPat = fopen("PAT.dat","rb+");

 

if(fpPat==NULL)

{

fpPat = fopen("PAT.dat","wb+");

if(fpPat == NULL)

{

puts("Can not open Source File");

getch();

exit(1);

}

}

 

recSizePat = sizeof(struct patient);

//////////////////////////////////

 

i=0;

 

rewind(fpPat);

 

while(fread(&patient[i],recSizePat,1,fpPat)==1)

{ i++; }

nPat=i;

//////////////////////////////////

 

////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////

 

fpDocPat = fopen("DOC_PAT.dat","rb+");

 

if(fpDocPat==NULL)

{

fpDocPat = fopen("DOC_PAT.dat","wb+");

if(fpDocPat == NULL)

{

puts("Can not open Source File");

getch();

exit(1);

}

}

 

recSizeDocPat = sizeof(struct DocPatVisit);

 

i=0;

 

rewind(fpDocPat);

 

while(fread(&DocPat[i],recSizeDocPat,1,fpDocPat)==1)

{ i++; }

nDocPat=i;

 

/////////////////////////////////////////////////////////////////////////////////////

while(isRun1)

{

printf("\n\n********************************************************************");

printf("\n Clinic Record Keeping System ");

printf("*******************************************************************************");

printf("\n\n1) Doctors List\n");

printf("\n2) Patients List\n");

printf("\n3) Doctors and Patients visits \n");

printf("\n4) Exit");

printf("\nEnter your choice : ");

scanf("%d",&choice);

isRun2=1;

///////////////////////////////////////////////////////////////////////////////////

switch(choice)

{

 

case 1:

while(isRun2)

{

printf("\n\n********************************************************************");

printf("\n DOCTORS LIST HANDLE ");

printf("*******************************************************************************");

printf("\n\n1.Input Record ( Over Write Old Records )\n");

printf("2.Insert Record\n");

printf("3.Search Record\n");

printf("4.Delete Record\n");

printf("5.Display Record\n");

printf("6.Save Record\n");

printf("7.Quit\n");

printf("\nEnter your choice : ");

scanf("%d",&choice);

 

switch(choice)

{

case 1:

printf("\nHow Many Records You Want To STORE : ");

scanf("%d",&nDoc);

inputDoctor(nDoc);

break;

case 2:

insertDoctor();

break;

case 3:

printf("Enter the Doctor Code to be searched : ");

scanf("%d", &ldocCode);

pos = searchDoctor(ldocCode);

if(pos >= 1)

{

printf("\n\nDoctor Code \t: %d", doc[pos-1].docCode);

printf("\nName \t\t: %s", doc[pos-1].name);

printf("\nAddress \t: %s", doc[pos-1].address);

printf("\nSpecialized in \t: %s", doc[pos-1].splIn);

 

}

else

printf("Record not found ...\n");

break;

case 4:

delDoctor();

break;

case 5:

printf("\n\nDoctors Lists ...");

displayDoctor();

break;

 

case 6:

printf("\nSave is Started\n");

 

//fseek(fpDoc,0,SEEK_END);

 

rewind(fpDoc);

 

for(i = 0; i< nDoc ; i++)

{

fwrite(&doc[i],recSizeDoc,1,fpDoc);

}

printf("\nSave is Completed\n");

 

break;

case 7:

isRun2=0;

break;

default:

printf("Wrong choice\n");

} /*End of switch */

}/*End of while */

//////////////////////// end of doc

 

break ; // end of case 1 of outer switch

 

//////////////////////////////////////////// pat /////////////////////////

case 2:

while(isRun2)

{

printf("\n\n*************************************************************************");

printf("\n PATIENT LIST HANDLE ");

printf("*******************************************************************************");

printf("\n\n1.Input Record ( Over Write Old Records )\n");

printf("2.Insert Record\n");

printf("3.Search Record\n");

printf("4.Delete Record\n");

printf("5.Display Record\n");

printf("6.Save Record\n");

printf("7.Quit\n");

printf("\nEnter your choice : ");

scanf("%d",&choice);

 

switch(choice)

{

case 1:

printf("\nHow Many Records You Want To STORE : ");

scanf("%d",&nPat);

inputPatient(nPat);

break;

case 2:

insertPatient();

break;

case 3:

printf("Enter the Patient Code to be searched : ");

scanf("%d", &lpatientCode);

pos = searchPatient(lpatientCode);

if(pos >= 1)

{

printf("\n\nPatient Code : %d", patient[pos-1].patientCode);

printf("\nPatient Name : %s", patient[pos-1].name);

printf("\nPatient Address : %s", patient[pos-1].address);

printf("\nPatient disease : %s", patient[pos-1].dis);

 

}

else

printf("Record not found ...\n");

break;

case 4:

delPatient();

break;

case 5:

printf("\n\nPatients Lists ...");

displayPatient();

break;

 

case 6:

// printf("\nSave is Started\n");

// fseek(fpPat,0,SEEK_START);

 

rewind(fpPat);

 

for(i = 0; i< nPat ; i++)

{

fwrite(&patient[i],recSizePat,1,fpPat);

}

printf("\nSave is Completed\n");

 

break;

case 7:

 

isRun2=0;

break;

default:

printf("Wrong choice\n");

} /*End of switch */

}/*End of while */

 

break;// end of Case 2 of Outer switch

/////////////////////////////////////////// end of pat//

 

case 3:

 

while(isRun2)

{

printf("\n\n********************************************************************");

printf("\n DOCTORS PATIENTS VISIT LIST HANDLE ");

printf("*******************************************************************************");

printf("\n\n1.Input Record ( Over Write Old Records )\n");

printf("2.Insert Record\n");

printf("3.Search Record\n");

printf("4.Delete Record\n");

printf("5.Display Record\n");

printf("6.Save Record\n");

printf("7.Quit\n");

printf("\nEnter your choice : ");

scanf("%d",&choice);

 

switch(choice)

{

case 1:

printf("\nHow Many Records You Want To STORE : ");

scanf("%d",&nDocPat);

inputDocPatVisit(nDocPat);

break;

/*

case 2:

insertDoctor();

break;

case 3:

printf("Enter the Doctor Code to be searched : ");

scanf("%d", &ldocCode);

pos = searchDoctor(ldocCode);

if(pos >= 1)

{

printf("\n\nDoctor Code : %d", doc[pos-1].docCode);

printf("\nDoctor Name : %s", doc[pos-1].name);

printf("\nDoctor Address : %s", doc[pos-1].address);

printf("\nDoctor Specialisd in : %s", doc[pos-1].splIn);

 

}

else

printf("Record not found ...\n");

break;

case 4:

delDoctor();

break;

*/

case 5:

printf("\n\nDoctors Patient Visits Lists ...");

displayDocPatVisit();

break;

 

case 6:

printf("\nSave is Started\n");

 

rewind(fpDocPat);

 

for(i = 0; i< nDocPat ; i++)

{

fwrite(&DocPat[i],recSizeDocPat,1,fpDocPat);

}

printf("\nSave is Completed\n");

 

break;

case 7:

isRun2=0;

break;

default:

printf("Wrong choice\n");

} /*End of switch */

}/*End of while */

//////////////////////// end of doc

 

break ; // end of case 3 of outer switch

 

 

case 4:

isRun1=0;

fclose(fpDoc);

fclose(fpPat);

fclose(fpDocPat);

break;

}// end of outer switch

}// end of while

}// end of main()

 

/////////////////////////////////////////////////////////

void inputDoctor()

{

int i,j,flag=0,ldocCode;

 

 

 

for(i = 0; i< nDoc ; i++)

{

AGAIN:

flag=0;

printf("\n\nInput Doctors Code for Doctor %d : ", i+1);

scanf("%d", &ldocCode);

for(j=0;j<i;j++)

{

if(ldocCode==doc[j].docCode)

{

flag=1;

break;

}

}

if(flag==1)

{

printf("\n\n.Doctors Code Already Available !!");

goto AGAIN;

}

else

doc[i].docCode=ldocCode;

 

fflush(stdin);

printf("\nInput Name for Doctor %d : ", i+1);

gets(doc[i].name);

printf("\nInput Addrress for Doctor %d : ", i+1);

gets(doc[i].address);

printf("\nInput Specialized in for Doctor %d : ", i+1);

gets(doc[i].splIn);

 

 

fflush(stdin);

 

}

}/*End of inputDoctor()*/

 

int searchDoctor(int ldocCode)

{

int i;

for(i=0; i < nDoc; i++)

{

if(ldocCode == doc[i].docCode)

return(i+1);

}

return(0); /* If element not found */

}/*End of searchDoctor()*/

 

void insertDoctor()

{

char lname[20],laddress[100],lsplin[30];

int j,temp,ldocCode,position,flag;

if(nDoc == MAX)

{

printf("\nThere Is No Space !!\n");

return;

}

AGAIN:

printf("Enter position for insertion : (1 to %d )",nDoc+1);

scanf("%d", &position);

if(position > nDoc+1 )

{

printf("\nEnter position less than or equal to %d\n",nDoc+1);

goto AGAIN;

}

 

ASK_DOC_CODE:

flag=0;

printf("\n\nInput Doctor Code for Doctor %d : ", position);

scanf("%d", &ldocCode);

for(j=0;j<nDoc;j++)

{

if(ldocCode==doc[j].docCode)

{

flag=1;

break;

}

}

if(flag==1)

{

printf("\n\nDoctor Code Already Available !!");

goto ASK_DOC_CODE;

}

 

fflush(stdin);

printf("\nInput Name for Doctor %d : ", position);

gets(lname);

printf("\nInput Address for Doctor %d : ", position);

gets(laddress);

printf("\nInput Specialized in for Doctor %d : ", position);

gets(lsplin);

 

 

if( position == nDoc+1 ) /*Insertion at the end */

{

doc[nDoc].docCode = ldocCode;

strcpy(doc[nDoc].name,lname);

strcpy(doc[nDoc].address,laddress);

strcpy(doc[nDoc].splIn,lsplin);

 

nDoc = nDoc+1;

return;

}

/* Insertion in between */

temp=nDoc-1;

while( temp >= position-1)

{

doc[temp+1].docCode = doc[temp].docCode; /* shifting right */

strcpy(doc[temp+1].name,doc[temp].name);

strcpy(doc[temp+1].address,doc[temp].address);

strcpy(doc[temp+1].splIn,doc[temp].splIn);

 

temp --;

}

 

doc[position-1].docCode = ldocCode;

strcpy(doc[position-1].name,lname);

strcpy(doc[position-1].address,laddress);

strcpy(doc[position-1].splIn,lsplin);

 

nDoc = nDoc +1 ;

}/*End of insertDoctor()*/

 

void delDoctor()

{

int temp,position,ldocCode;

if(nDoc == 0)

{

printf("\nList underflow\n");

return;

}

printf("\nEnter the Doctor Code to be deleted : ");

scanf("%d",&ldocCode);

if(ldocCode == doc[nDoc-1].docCode) /*Deletion at the end*/

{

nDoc = nDoc-1;

return;

}

position=searchDoctor(ldocCode);

if(position==0)

{

printf("\nRecord Not Found ...\n");

return;

}

/*Deletion in between */

temp=position-1;

while(temp <= nDoc-1)

{

doc[temp].docCode = doc[temp+1].docCode; /* Shifting left */

strcpy(doc[temp].name,doc[temp+1].name);

strcpy(doc[temp].address,doc[temp+1].address);

strcpy(doc[temp].splIn,doc[temp+1].splIn);

 

temp ++;

}

nDoc = nDoc - 1 ;

}/*End of delDoctor()*/

 

void displayDoctor()

{

int i;

if(nDoc==0)

{

printf("\nDoctors is empty !!\n");

return;

}

for(i = 0; i< nDoc; i++)

{

printf("\n\nDoctor Code \t: %d", doc[i].docCode);

printf("\nName \t\t: %s", doc[i].name);

printf("\nAddress \t: %s", doc[i].address);

printf("\nSpecialized in \t: %s", doc[i].splIn);

}

}/*End of displayDoctor()*/

 

///////////////////////////////////////////////////////////////////////////////////////////////////////////////

 

///////////////////////////////////////////////////////////////////////////////////////////////////////////////

void inputPatient()

{

int i,j,flag=0,lpatientCode;

 

 

 

for(i = 0; i< nPat ; i++)

{

AGAIN:

flag=0;

printf("\n\nInput Patients Code for Patient %d : ", i+1);

scanf("%d", &lpatientCode);

for(j=0;j<i;j++)

{

if(lpatientCode==patient[j].patientCode)

{

flag=1;

break;

}

}

if(flag==1)

{

printf("\n\nPatients Code Already Available !!");

goto AGAIN;

}

else

patient[i].patientCode=lpatientCode;

 

fflush(stdin);

printf("\nInput Name for Patient %d : ", i+1);

gets(patient[i].name);

printf("\nInput Addrress for Patient %d : ", i+1);

gets(patient[i].address);

printf("\nInput disease of Patient %d : ", i+1);

gets(patient[i].dis);

 

fflush(stdin);

 

}

}

//End of inputPatient()

 

int searchPatient(int lpatientCode)

{

int i;

for(i=0; i < nPat; i++)

{

if(lpatientCode == patient[i].patientCode)

return(i+1);

}

return(0); /* If element not found */

}/*End of searchPatient()*/

 

void insertPatient()

{

char lname[20],laddress[100],l_dis[30];

int j,temp,lpatientCode,position,flag;

if(nPat == MAX)

{

printf("\nThere Is No Space !!\n");

return;

}

AGAIN:

printf("Enter position for insertion : (1 to %d )",nPat+1);

scanf("%d", &position);

if(position > nPat+1 )

{

printf("\nEnter position less than or equal to %d\n",nPat+1);

goto AGAIN;

}

 

ASK_PAT_CODE:

flag=0;

printf("\n\nInput Patient Code for Patient %d : ", position);

scanf("%d", &lpatientCode);

for(j=0;j<nPat;j++)

{

if(lpatientCode==patient[j].patientCode)

{

flag=1;

break;

}

}

if(flag==1)

{

printf("\n\nPatient Code Already Available !!");

goto ASK_PAT_CODE;

}

 

fflush(stdin);

printf("\nInput Name for Patient %d : ", position);

gets(lname);

printf("\nInput Address for Patient %d : ", position);

gets(laddress);

printf("\nInput disease of Patient %d : ", position);

gets(l_dis);

 

 

if( position == nPat+1 ) /*Insertion at the end */

{

patient[nPat].patientCode = lpatientCode;

strcpy(patient[nPat].name,lname);

strcpy(patient[nPat].address,laddress);

strcpy(patient[nPat].dis,l_dis);

 

nPat = nPat+1;

return;

}

/* Insertion in between */

temp=nPat-1;

while( temp >= position-1)

{

patient[temp+1].patientCode = patient[temp].patientCode; /* shifting right */

strcpy(patient[temp+1].name,patient[temp].name);

strcpy(patient[temp+1].address,patient[temp].address);

strcpy(patient[temp+1].dis,patient[temp].dis);

 

temp --;

}

 

patient[position-1].patientCode = lpatientCode;

strcpy(patient[position-1].name,lname);

strcpy(patient[position-1].address,laddress);

strcpy(patient[position-1].dis,l_dis);

 

nPat = nPat +1 ;

}/*End of insertPatient()*/

 

void delPatient()

{

int temp,position,lpatientCode;

if(nPat == 0)

{

printf("\nList underflow\n");

return;

}

printf("\nEnter the Patient Code to be deleted : ");

scanf("%d",&lpatientCode);

if(lpatientCode == patient[nPat-1].patientCode) /*Deletion at the end*/

{

nPat = nPat-1;

return;

}

position=searchPatient(lpatientCode);

if(position==0)

{

printf("\nRecord Not Found ...\n");

return;

}

/*Deletion in between */

temp=position-1;

while(temp <= nPat-1)

{

patient[temp].patientCode = patient[temp+1].patientCode; /* Shifting left */

strcpy(patient[temp].name,patient[temp+1].name);

strcpy(patient[temp].address,patient[temp+1].address);

strcpy(patient[temp].dis,patient[temp+1].dis);

 

temp ++;

}

nPat = nPat - 1 ;

}/*End of delPatient()*/

 

void displayPatient()

{

int i;

if(nPat == 0)

{

printf("\nPatients List is empty !!\n");

return;

}

for(i = 0; i< nPat ; i++)

{

printf("\n\nPatient Code \t: %d", patient[i].patientCode);

printf("\nName \t\t: %s", patient[i].name);

printf("\nAddress \t: %s", patient[i].address);

printf("\ndisease \t: %s", patient[i].dis);

}

}/*End of displayPatient()*/

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

 

///////////////////////////////////////////////////////////////////////////////////////////////////////////////

void inputDocPatVisit()

{

int i,j,flag=0,lpatientCode,lDocCode;

 

for(i = 0; i< nDocPat ; i++)

{

////////////////////

AGAIN_Doc:

flag=0;

printf("\nAvailable Doctors");

printf("\n------------------------------------------------------------");

 

displayDoctor();

printf("\n------------------------------------------------------------");

printf("\n\nInput Doctor Code for Doctor Patient Visit %d : ", i+1);

scanf("%d", &lDocCode);

for(j=0;j<nDoc ;j++)

{

if(lDocCode==doc[j].docCode)

{

flag=1;

break;

}

}

if(flag==0)

{

printf("\n\nDoctor Code is Not Available !!");

goto AGAIN_Doc;

}

else

DocPat[i].docCode =lDocCode;

/////////////////////////////////////

AGAIN_Pat:

flag=0;

printf("\nAvailable Patients");

printf("\n------------------------------------------------------------");

 

displayPatient();

 

printf("\n------------------------------------------------------------");

 

printf("\n\nInput Patient Code for Doctor Patient Visit %d : ", i+1);

scanf("%d", &lpatientCode);

for(j=0;j<nPat;j++)

{

if(lpatientCode==patient[j].patientCode)

{

flag=1;

break;

}

}

if(flag==0)

{

printf("\n\nPatient Code is Not Available !!");

goto AGAIN_Pat;

}

else

DocPat[i].patCode =lpatientCode;

 

fflush(stdin);

printf("\nInput Date for Doctor Patient Visit %d : ", i+1);

gets(DocPat[i].DatOfVisit);

printf("\nInput Remarks for Doctor Patient Visit %d : ", i+1);

gets(DocPat[i].Remark);

 

fflush(stdin);

 

}

}/*End of inputDocPatVisit()*/

/*

int searchDocPatVisit(int lpatientCode)

{

int i;

for(i=0; i < nPat; i++)

{

if(lpatientCode == patient[i].patientCode)

return(i+1);

}

return(0); // If element not found

}

// End of searchDocPatVisit()

 

void insertDocPatVisit()

{

char lname[20],laddress[100],l_dis[30];

int j,temp,lpatientCode,position,flag;

if(nPat == MAX)

{

printf("\nThere Is No Space !!\n");

return;

}

AGAIN:

printf("Enter position for insertion : (1 to %d )",nPat+1);

scanf("%d", &position);

if(position > nPat+1 )

{

printf("\nEnter position less than or equal to %d\n",nPat+1);

goto AGAIN;

}

 

ASK_PAT_CODE:

flag=0;

printf("\n\nInput DocPatVisit Code for DocPatVisit %d : ", position);

scanf("%d", &lpatientCode);

for(j=0;j<nPat;j++)

{

if(lpatientCode==patient[j].patientCode)

{

flag=1;

break;

}

}

if(flag==1)

{

printf("\n\nDocPatVisit Code Already Available !!");

goto ASK_PAT_CODE;

}

 

fflush(stdin);

printf("\nInput Name for DocPatVisit %d : ", position);

gets(lname);

printf("\nInput Address for DocPatVisit %d : ", position);

gets(laddress);

printf("\nInput disease of DocPatVisit %d : ", position);

gets(l_dis);

 

 

if( position == nPat+1 ) //Insertion at the end

{

patient[nPat].patientCode = lpatientCode;

strcpy(patient[nPat].name,lname);

strcpy(patient[nPat].address,laddress);

strcpy(patient[nPat].dis,l_dis);

 

nPat = nPat+1;

return;

}

// Insertion in between

temp=nPat-1;

while( temp >= position-1)

{

patient[temp+1].patientCode = patient[temp].patientCode; //shifting right

strcpy(patient[temp+1].name,patient[temp].name);

strcpy(patient[temp+1].address,patient[temp].address);

strcpy(patient[temp+1].dis,patient[temp].dis);

 

temp --;

}

 

patient[position-1].patientCode = lpatientCode;

strcpy(patient[position-1].name,lname);

strcpy(patient[position-1].address,laddress);

strcpy(patient[position-1].dis,l_dis);

 

nPat = nPat +1 ;

}

 

// End of insertDocPatVisit()

 

void delDocPatVisit()

{

int temp,position,lDocPatCode;

if(nDocPat == 0)

{

printf("\nList underflow\n");

return;

}

printf("\nEnter the DocPatVisit Code to be deleted : ");

scanf("%d",&lpatientCode);

if(lpatientCode == patient[nPat-1].patientCode) // Deletion at the end

{

nPat = nPat-1;

return;

}

position=searchDocPatVisit(lpatientCode);

if(position==0)

{

printf("\nRecord Not Found ...\n");

return;

}

// Deletion in between

temp=position-1;

while(temp <= nPat-1)

{

patient[temp].patientCode = patient[temp+1].patientCode; // Shifting left

strcpy(patient[temp].name,patient[temp+1].name);

strcpy(patient[temp].address,patient[temp+1].address);

strcpy(patient[temp].dis,patient[temp+1].dis);

 

temp ++;

}

nPat = nPat - 1 ;

}

*/

 

//End of delDocPatVisit()

 

 

void displayDocPatVisit()

{

int i;

int ldocIndex ,lPatIndex;

if(nDocPat == 0)

{

printf("\nDoctor Patient Visits List is empty !!\n");

return;

}

for(i = 0; i< nDocPat ; i++)

{

ldocIndex=searchDoctor(DocPat[i].docCode);

ldocIndex--;

printf("\n----------------------------------------------------------");

printf("\nDoctor Name : %s ",doc[ldocIndex].name);

printf("\nDoctore Specialisd in : %s ",doc[ldocIndex].splIn);

printf("\n----------------------------------------------------------");

 

 

lPatIndex=searchPatient(DocPat[i].patCode );

lPatIndex--;

 

printf("\nPatient Name : %s ", patient[i].name);

printf("\nPatient disease : %s ", patient[i].dis);

printf("\n----------------------------------------------------------");

 

printf("\nDate of Visit : %s ", DocPat[i].DatOfVisit);

printf("\nRemarks : %s ", DocPat[i].Remark);

printf("\n----------------------------------------------------------");

}

}/*End of displayDocPatVisit()*/

 

 

=======================================================================

 

 

Section 2: Assembly Language Programming Lab

Question 1:

 

(a) Write a program in assembly language to sort an array of signed integers and search for the presence of an item in the sorted array using linear search

(5 Marks)

 

(b) Develop and execute an assembly language program to find the HCF of two unsigned 16-bit numbers.

(5 Marks)

 

(c ) Write a program in assembly language for finding the largest number in an array of 10 elements. (5 Marks)

(d) Given a string of characters terminated by 00H, write a assembly language program to determine if it is a palindrome. If 'Yes' output the message " The given string is a palindrome. If 'No' output the message "No, it is not a palindrome"

(5 Marks)

 

Solution: Coming soon..

 

 

==========================================================================================================================================================================================THE END===================================





Attachment:

( 0 Votes )

Add comment


Security code
Refresh

Earning:   Approval pending.
You are here: PAPER Indira Gandhi National TribalUniversity, Amarkantak 2011 M.C.A Problem Solving and Programming (Assignment) - Question Paper