You are on page 1of 13

MCSL-017 C and Assembly Programming 2019

Language

MCSL-017 Solved Assignment 2019-20

Section 1: C Programming Lab

Q1.)Write an interactive application program in C language to create and maintain


information of the students of a School. You must use files and structure to develop
the application.

The application should store the following data: Student ID, Student Name, Class of
the student, percentage of marks obtained by the student in last class and contact
phone of the parents of the student. This application should support the following
operations of the student data (you can design a simple menu option for each
operation)
Creating a New student Record
Searching the data of a student based on his/her ID or
name. Listing of all the Records of a class
Modifying the record of a student

The application should be user-friendly.

Ans : //Application for the Student information System. in C Language

#include<stdio.h>
struct student
{
int s_id;
char name[30];
char class[5];
float p_mark;
long int parents_phoneno;
}stud;
// FUNCTION TO INSERT RECORDS TO THE FILE
void insert()
{
FILE *fp;
fp = fopen("Record.txt", "a+");
printf("Enter the Student Id
:");
scanf("%d", &stud.s_id);
printf("Enter the Name :");
scanf("%s", &stud.name);
printf("Enter the Percentage of mark :");
scanf("%f", &stud.p_mark);
printf("Enter Student previous class :");
scanf("%s",&stud.class);
printf("Enter Parents Phone Number :");
scanf("%ld",&stud.parents_phoneno);

https://myignou4u.blogpsot.com Page 1
MCSL-017 C and Assembly Programming 2019
Language
fwrite(&stud, sizeof(stud), 1, fp);

https://myignou4u.blogpsot.com Page 2
fclose(fp);
}
// FUNCTION TO DISPLAY RECORDS
void disp()
{
FILE *fp1;
fp1 = fopen("Record.txt", "r");
printf("\nStudent_ID\tName\tClass\tPercentage of Mark\tParents
PhoneNo \n\n");
while (fread(&stud, sizeof(stud), 1, fp1))
printf(" %d\t\t%s\t%s\t\t%.2f\t%ld\n\n", stud.s_id, stud.name,
stud.class,stud.p_mark,stud.parents_phoneno);
fclose(fp1);
}
// FUNCTION TO SEARCH THE GIVEN RECORD
void search()
{
FILE *fp2;
int id, s, avl;
printf("\nEnter the Student Id you want to search :");
scanf("%d", &id);
avl = avlrollno(id);
if (avl == 0)
printf("ID No %d is not available in the file\n",id);
else
{
fp2 = fopen("Record.txt", "r");
while (fread(&stud, sizeof(stud), 1, fp2))
{
s = stud.s_id;
if (s == id)
{
printf("\nRoll no = %d", stud.s_id);
printf("\nName = %s", stud.name);
printf("\nClass =%s", stud.class);
printf("\nMark = %.2f\n", stud.p_mark);
printf("\nParents PhoneNo =%ld",stud.parents_phoneno);
}
}
fclose(fp2);
}
}
// FUNCTION TO DELETE A RECORD

void deletefile()
{
FILE *fpo;
FILE *fpt;
int r, s;
printf("Enter the Roll no you want to delete :");
scanf("%d", &r);
if (avlrollno(r) == 0)
printf("Roll no %d is not available in the file\n", r);
else
{
fpo = fopen("Record.txt", "r");
fpt = fopen("TempFile.txt", "w");
while (fread(&stud, sizeof(stud), 1, fpo))
{
s = stud.s_id;
if (s != r)
fwrite(&stud, sizeof(stud), 1, fpt);
}
fclose(fpo);
fclose(fpt);
fpo = fopen("Record.txt", "w");
fpt = fopen("TempFile.txt", "r");
while (fread(&stud, sizeof(stud), 1, fpt))
fwrite(&stud, sizeof(stud), 1, fpo);
printf("\nRECORD DELETED\n");
fclose(fpo);
fclose(fpt);
}

}
// FUNCTION TO UPDATE THE RECORD
void update()
{
int avl;
FILE *fpt;
FILE *fpo;
int s, id, ch;
printf("Enter Student Id number to update:");
scanf("%d", &id);
avl = avlrollno(id);
if (avl == 0)
{
printf("ID number %d is not Available in the file", id);
}
else
{
fpo = fopen("Record.txt", "r");
fpt = fopen("TempFile.txt", "w");
while (fread(&stud, sizeof(stud), 1, fpo))
{
s = stud.s_id;
if (s != id)
fwrite(&stud, sizeof(stud), 1, fpt);
else
{
printf("\n\t1. Update Name of id Number %d", id);
printf("\n\t2. Update Mark of id Number %d", id);
printf("\n\t3. Update both Name and Mark of id Number %d", id);
printf("\nEnter your choice:");
scanf("%d", &ch);
switch (ch)
{
case 1:
printf("Enter Name:");
scanf("%s", &stud.name);
break;
case 2:
printf("Enter parecentage Mark : ");
scanf("%f", &stud.p_mark);
break;
case 3:
printf("Enter Name: ");
scanf("%s", &stud.name);
printf("Enter Mark: ");
scanf("%f", &stud.p_mark);
break;
default:
printf("Invalid Selection");
break;
}
fwrite(&stud, sizeof(stud), 1, fpt);
}
}
fclose(fpo);
fclose(fpt);
fpo = fopen("Record.txt", "w");
fpt = fopen("TempFile.txt", "r");
while (fread(&stud, sizeof(stud), 1, fpt))
{
fwrite(&stud, sizeof(stud), 1, fpo);
}
fclose(fpo);
fclose(fpt);
printf("RECORD UPDATED");
}
}
//CTION TO CHECK GIVEN ROLL NO IS AVAILABLE //
int avlrollno(int idno)
{
FILE *fp;
int c = 0;
fp = fopen("Record.txt", "r");
while (!feof(fp))
{
fread(&stud, sizeof(stud), 1, fp);

if (idno == stud.s_id)
{
fclose(fp);
return 1;
}
}
fclose(fp);
return 0;
}
//FUNCTION TO CHECK THE FILE IS EMPTY OR NOT
int empty()
{
int c = 0;
FILE *fp;
fp = fopen("Record.txt", "r");
while (fread(&stud, sizeof(stud), 1, fp))
c = 1;
fclose(fp);
return c;
}
// MAIN PROGRAM
void main()
{
int c, emp;
do
{
printf("\n\t---Select your choice----------------\n");
printf("\n\t1. INSERT\n\t2. DISPLAY\n\t3. SEARCH");
printf("\n\t4. DELETE\n\t5. UPDATE\n\t6. EXIT");
printf("\n\n \n");
printf("\nEnter your choice:");
scanf("%d", &c);
printf("\n");
switch (c)
{
case 1:
insert();
break;
case 2:
emp = empty();
if (emp == 0)
printf("\nThe file is EMPTY\n");
else
disp();
break;
case 3:
search();
break;
case 4:
deletefile();
break;
case 5:
update();
break;
case 6:
exit(1);
break;
default:
printf("\nYour choice is wrong\nPlease try again...\n");
break;

}
} while (c != 6);
}

Screen Shot of Application


END OF SECTION-1
Section 2: Assembly Language Programming Lab
Q1.
a) Write a program using 8086 assembly language to find the sum and average of five,
byte numbers stored in the consecutive memory locations. (5 Marks)

Ans:
DATA SEGMENT
NUM1 DB 5
NUM2 DB 9
NUM3 DB 7
NUM4 DB 8
NUM5 DB 4
AVG DB ?
SUM DB ?
ENDS
CODE SEGMENT
ASSUME DS:DATA CS:CODE
START:
MOV AX,DATA
MOV DS,AX
MOV AL,NUM1
ADD AL,NUM2
ADD AL,NUM3
ADD AL,NUM4
ADD AL,NUM5
MOV AH,0
MOV DL,5
DIV DL
MOV SUM,AL
MOV AVG,AL
MOV AH,4CH
INT 21H
ENDS
END START

b) Write a program using 8086 assembly language to find the largest of the four
numbers stored in four differently named locations in the memory. (5 Marks)

Ans: DATA SEGMENT


DATA SEGMENT

X DW 0010H,52H,30H,40H,50H

LAR DW ?

DATA ENDS

CODE SEGMENT

ASSUME CS:CODE,DS:DATA

START: MOV AX,DATA

MOV DS,AX

MOV CX,05H

LEA SI,X

MOV AX,[SI]

DEC CX

UP: CMP AX,[SI+2]

JA CONTINUE

MOV AX,[SI+2]

CONTINUE:ADD SI,2
DEC CX

JNZ UP

MOV LAR,AX

MOV AH,4CH

INT 21H

CODE ENDS

END START

c) Write a program using 8086 assembly language to pass an ASCII value in AL register
to a near subroutine named printval. The subroutine should print the value passed to it
using interrupt 21h. (5 Marks)

Ans:

DATA SEGMENT
MSG1 DB 10,13,"ENTER ANY ASCII VALUE : $"
MSG2 DB 10,13,"PRINTING AL VALUE : $"
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START:
MOV AX,DATA
MOV DS,AX
LEA DX,MSG1
MOV AH,9
INT 21H
CALL PRINTVAL
MOV AH,4CH
INT 21H
CODE ENDS
PRINTVAL PROC NEAR
MOV AH,1
INT 21H
MOV BL,AL
LEA DX,MSG2
MOV AH,9
INT 21H
MOV DL,BL
MOV AH,2
INT 21H
RET
PRINTAL ENDP
END START

d) Write a program using 8086 assembly language that reads two separate digits
as input from the keyboard and converts them to equivalent packed BCD number.
For example, if the two digits are - '3' and '5' then the packed BCD will be (35)h . (5
Marks)

Ans :

DATA SEGMENT

MSG1 DB "ENTER NUMBER : $"

DIGIT1 DB ?

DIGIT2 DB ?

BCD DB ?

DATA ENDS

CODE SEGMENT

ASSUME DS:DATA,CS:CODE

START:

MOV AX,DATA

MOV DS,AX

LEA DX,MSG1

MOV AH,9

INT 21H

MOV AH,1
INT 21H

SUB AL,30H

MOV DIGIT1,AL

MOV AH,1

INT 21H

SUB AL,30H

MOV DIGIT2,AL

MOV AH,DIGIT1

MOV AL,DIGIT2

MOV CL,4

ROL AH,CL

ADD AL,AH

MOV BCD,AL

CODE ENDS

END START

You might also like