You are on page 1of 12

Q:1

Write an interactive program in c language to manage the working of a construction


company. Implement and manage the records with suitable data structures of the
company and their states(proposal, installation, maintenance, yearly contract etc.),
the business turnovers of the company, salaries of the employees, present
assignments of the employees and details of the clients. The application should be
designed user friendly.

Ans:-

#include<stdio.h>
#include<conio.h>
#include<math.h>

struct EmpData

{
int empid;
char ename[60];
float salary;
float da,ta;
int pid;
}emp;

struct project

{
int pid;
char pname[60];
}pro;

main()

{
FILE *fp;
FILE *fp1;

char ans, choice, ch1;


int rec,st;

rec=sizeof(emp);

fp=fopen("d:\\emp.dat","a+");

do
{

clrsc();
gotoxy();
textcolor(4);

printf("\nEmployee Management System");


printf("\n\n");

printf("\n\t\t\t[A]Add record:");
printf("\n");

printf("\n\n[E]Employee Add record:");


printf("\n\n[P]Project Add record:");

printf("\n\n");
printf("\n\t\t\t[L]List Record:");
printf("\n\t\t\t[S]Search Record:");
printf("\n\t\t\t[D]Delete Record:");
printf("\n\t\t\t[X]Exit System:");
printf("\n\t\t\tEnter Your Choice:");
fflush(stdin);
scanf("%c",&choice);

if(choice=='a'||choice=='A')
{
printf("\nEmployee Management System");
printf("\n\n");

printf("\n\n[E]Employee Add Record:");


printf("\n\n[P]Project Add Record:");

printf("\n\n");
printf("\n\t\t\Enter Your Choice:");
fflush(stdin);
scanf("%c",&choice);

if(ch1=='e'||ch1=='E')
{
clrscr();
gotoxy(25,2);
textcolor(6);
printf("\nEmployee Mangement System");
printf("\n\n");
fseek(fp,0,SEEK_END);
printf("\n\n\nEnter Employee ID:");
scanf("%d",&emp.empid);
printf("\n\n\nEnter Employee Name:");
gets(emp.ename);
printf("\n\n\nEnter Employee Salary:");
scanf("%f",&emp.salary);
printf("\n\nEnter Project Status:");
scanf("%d",&emp.pid);
emp.da=(emp.salary*0.15);
emp.ta=(emp.salary*0.10);
fwrite(&emkp.rec,1,fp);
fclose(fp);
}
else
{
fp=fopen("d:\emp.dat","a+");
clrscr();

gotoxy(25,2);
textcolor(6);
printf("\nEmployee Mangemeent System");
printf("\n\n");
fseek(fp,0,SEEK_END);

printf("\n\n\nEnter Project ID:");


scanf("%d",&pro.pid);
printf("\n\n\nEnter Project Name:");
gets(pro.pname);
fwrite(&pro.rec,1,fp);
fclose(fp);
}
}

else if(choice=='L'||choice=='l')
{
clrscr();
gotoxy(25,2);
textcolor(6);

printf("\nEmployee Management System");


printf("\n\n");
rewind(fp);
printf("\nEmpID\tName\tSalary\tTA\tDA\tProject Total");
printf("\n----------------------------------------------\n");

while(fread(&emp.rec,1,fp)==1)
{
printf("\n%d\t\t%s\t\t%2f\t\t%2f\t\t%d\t\t
%2f",emp.empid,emp.empname,emp.salary,emp.ta,emp.da,emp.pid(emp.salary+emp.ta+
emp.da));
}

getch();
}

else if(choice=='S'||choice=='s')
{
int no,s=0;
clrscr();
printf("\nEnter no to search:");
fflush(stdin);
scanf("%d",&no);
clrscr();
gotoxy(25,2);
textcolor(6);

printf("\nEmployee Management System");


printf("\n\n");
rewind(fp);

printf("\nEmp ID\tName\tSalary\tTA\tDA\tTotal");
printf("\n---------------------------------------\n");

while(fread(&emp.rec,1,fp)==1)
{
if(no==emp.empid)
{
printf("\n%d\t\t%s\t\t%2f\t\t%2f\t\t%2f\t\t%d\t\t
%2femp.empid,emp.empname,emp.salary,emp.ta,emp.da,emp.pid(emp.salary+emp.ta+e
mp.da));
s++;
break;
}

if(s==0)
printf("\nNO DATA FOUND");
getch();
}

gotoxy(25,40);
printf("\nDo you want to continue...(Y or N)");
scanf("%c",&ans);

}while(ans=='y'|ans=='Y');
printf("BYE..!!");
getch();
return 0;
}
Q:2-(A)

Write a program in 8086 assembly language that convert two four digit
number into its equivalent packed BCD. Also it compares that numbers
and display the large one. In case the numbers are same then zero can
be displayed.

Answer:

MY_DATA SEGMENT
NUM1 DB'1234'
NUM2 DB'1235'
UNPK_NUM1 DW?
UNPK NUM2 DW?
MAX_NUM DW?
MY_DATA ENDS

MY_CODE SEGMENT
ASSUME CS:MY_CODE, DS:MY_DATA
START: MOV AX,MY_DATA
MOV DS, AX
LEA SI, NUM1
MOV AH,[SI]
INC SI
MOV AL,[SI]
AND AH, 0FH
ROL AH, 0FH
ROL AH, 04H
OR AH, AL
INC SI
MOV BH, [SI]
INC SI
MOV BL, [SI]
AND BH, 0FH
AND BL, 04H
ROL BH, 04H
OR BH, BHL
MOV AL, BH
MOV UNPK_NUM1, AX
LEA SI, NUM2
MOV AH, [SI]
AND AH, 0FH
AND AL, 0FH
AND AH, 04H
ROL AH, 04H
OR AH, 04H
INC SI
MOV BH, [SI]
INC SI
MOV BL, [SI]
AND BH, 0FH
AND BL, 0FH
ROL BH, 04H
OR BH, 04H

MOV AL, BH
MOV UNPK_NUM2, AX
CMP AX, BX
JA LI
MOV MAX_NUM, BX
JMP L2
L1: MOV MAX_NUM, AX
L2: INT 21H

MY_CODE ENDS

END START
Q:2-(B)

Write a program in 8086 assembly language that accept a string from


the keyboard and then reverse a string using stack. The string can be
assumed to be available in the data segment.

Ans:

PTRSTR MACRO MS
MOV AH, 09H
LEA DX, MS
INT 21H
ENDM

DATA SEGMENT
STR1 DB 20
DB 20 DUP('$)
CRLF DB 0AH,0DH,$
STR2 DB 20
DB 0
DB 20 DUP('$')
MSG1 DB"ENTER A STRING:$"
MSG2 DB"REVERSE OF GIVEN STRING:$"
DATA ENDS

STACK_SEG SEGMENT
DB 25 DUP(?)
TOP_STACK LABEL BYTE
STACK_SEG ENDS

CODE SEGMENT
ASSUME CS: CODE, DATA, ES: DATA, SS: STACK_SEG

START
MOV AX, DATA
MOV DS, AX
MOV ES, AX
MOV AX, STACK_SEG
PTRSTR MSG1

MOV AH, 0AH


LEA DX, STR1
INT 21H
MOV CX, 00
MOV DL, 00

LEA SI, STR1+1


LEA DI, STR2+2
MOV BL,'$'

L2: PUSH[SI]
CMP[SI], BL
JE L1
INC SI

JMP L2
L1: POP AX
MOV[DI], AX
CMP AL, BL
JE L3
JMP L2
L3: PTRSTR CRLF
PTRSTR MSG2
PTRSTR STR2+2

MOV AH, 4CH


INT 21H
CODE ENDS
END START
Q:2-©

Write a program in 8086 assembly language that devide a 16-bit


number stored in memory location 2501 and 2502h with an 8-bit divisor
is stored in location 2503h.
Store the quotient in 2504h and remainder in 2505h...

Ans:

MY DATA SEGMENT

BLANK_MEMORY_BLOCK DB 2501H DUP(?)


DIVIDEND DW 105H; 16 BIT NUMBER STORED ON 2501H AND 2502
DIVISOR DB 10H ; 8 BITDIVISOR ON 2503H
QUOTIENT DB? ; 8 BIT QUOTIENT ON 2504H
REMEAINDER DB?

MY_DATA ENDS

MY_CODE SEGMENT
ASSUME CS: MY_CODE, DS: MY_DATA
START: MOV AX, MY_DATA
MOV DS, AX
MOV AX, DIVIDENT
MOV BL, DIVISOR
DIV BL
MOV QUOTIENT, AL
MOV REMAINDER, AH
INT 21H

MY_CODE ENDS

END START
Q:2-(D)

Write a program in 8086 assembly language to evaluate 6*(x^2)+5x+9 If


flag==1 or 4*(x^2)+7 if flag==0. Assume x is a 16bit unsigned integer:

Ans:

MY_DATA SEGMENT
X DW 2H
FLAG DB 0
RESULT DW?
MY_DATA ENDS

MY_CODE SEGMENT
ASSUME CS: MY_CODE, DS: MY_DATA
START: MOV AX, MY_DATA
MOV DS, AX

MOV AL, FLAG


CMP AL, 0
JZ L1
MOV AX, X
MUL AX
MOV BL, 6
MUL BL

MOV BX, AX
MOV CL, 5
MOV AX, X
MUL CL
ADD AX, 9
ADC AX, BX
JMP L2
L1: MOV AX, X
MUL AX
MOV BL, 4MUL BL
ADD AX, 7
L2: MOV RESULT, AX
INT 21H
MY_CODE ENDS

END START