Reading/Listing of Records
Modify the record
Delete the record
Each employee record should have Employee Name, Employee ID,Department Name, Salary,
Position, Date of Joining, etc). The application should be designed user-friendly.
A.1.
Structure is a user-defined data type in C which allows you to combine different data types to store a
particular type of record. Structure helps to construct a complex data type in more meaningful way. It is
somewhat similar to an Array. The only difference is that array is used to store collection of similar data
types while structure can store collection of any type of data.
Structure is used to represent a record. Suppose you want to store record of Student which consists of
student name, address, roll number and age. You can define a structure to hold this information.
Array of Structure:
We can declare an array of structure. Each element of the array representing a structure variable.
Example : struct employee emp[5];
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define size 200
struct emp
{
int emp_id;
char *emp_name;
char *Dept_name;
float Salary;
char *Pos;
int Date;
}*emp1, *emp3;
void create();
void display();
void update();
void delete();
if (fp1 == NULL)
printf("\nFile not opened for reading");
while (i <= count)
{
fread(&emp3->emp_id, sizeof(emp3->emp_id), 1, fp1);
fread(emp3->emp_name, size, 1, fp1);
printf("\n%d %s",emp3->emp_id,emp3->emp_name);
i++;
}
fclose(fp1);
free(emp3->emp_name);
free(emp3);
}
void update()
{
int id, flag = 0, i = 1;
char s[size];
if (fp1 == NULL)
{
printf("File cant be opened");
return;
}
printf("Enter employee id to update : ");
scanf("%d", &id);
emp3 = (struct emp *)malloc(1*sizeof(struct emp));
emp3->emp_name=(char *)malloc(size*sizeof(char));
while(i<=count)
{
fread(&emp3->id, sizeof(emp3->emp_id), 1, fp1);
fread(emp3->emp_name,size,1,fp1);
if (id == emp3->emp_id)
{
printf("Enter new name of emplyee to update : ");
scanf(" %[^\n]s", s);
fseek(fp1, -204L, SEEK_CUR);
fwrite(&emp3->emp_id, sizeof(emp3->id), 1, fp1);
fwrite(s, size, 1, fp1);
flag = 1;
break;
}
i++;
}
if (flag != 1)
{
printf("No employee record found");
flag = 0;
}
fclose(fp1);
free(emp3->name); /* to free allocated memory */
free(emp3);
}
$ a.out emprec1
1] Create a Record
2] Display Records
3] Update Records
4] Delete Record
5] Exit
C Programming Lab
CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START:
MOV AX,DATA
MOV DS,AX
MOV AL,A
MOV AH,B
MOV BL,AL
MOV AL,AH
MOV AH,BL
MOV A,AL
MOV B,AH
MOV AX,4C00H
INT 21H
CODE ENDS
END START
OUTPUT
***********
BEFOR AFTER
ax 0000 ax 06C1
bx 0000 bx CD36
c) Write a program in assembly language to load a byte in memory location 8000H and
increment the contents of the memory location.
A.1.(c)
Program 1:
MVI A, 32H : Store 32H in the accumulator
STA 4000H : Copy accumulator contents at address 4000H HLT : Terminate program execution
Program 2: LXI H : Load HL with 4000H MVI M : Store 32H in memory location pointed by HL register pair
(4000H)
Cr EQU 0ah
Lf EQU 0dh
data SEGMENT
p_num DB cr, lf, 'Enter a number: ',0
p_rev DB cr, lf,'The reverse is: ',0
ten DW ?
tmpstr DW 40 DUP (?)
data ENDS
code SEGMENT
ASSUME cs:code, ds:data
start: mov ax, data
mov ds, ax
;input the number
output p_num
inputs tmpstr, 10
atoi tmpstr
;initialize
mov cx, 00h;stores the reverse number
mov ten, 10
;iterate to reverse digits
next: cmp ax, 0
jz op_rev;exit the loop if number=0
cwd
idiv ten;to extract units digit
mov bx, dx;to save contents of dx
xchg ax, cx;to perform multiplication
imul ten;to insert units digit
add ax, bx;add the acutal units digit
xchg ax, cx;save the reverse number back
jmp next
;output the reverse
op_rev: output p_rev
itoa tmpstr, cx
output tmpstr
END start