Sunday 26 February 2017

MCA Ist sem /MCSL-017/Solved Assignment/C And Assembly Language Programming /2016-2017 New

                               Section 1 : C Programming Lab


1.Write an interactive program in C language to create an application program for your study centre. This application should be having menu options like student‟s details (Name, Enrollment, Address, Programme, course, contact, etc), semester enrolled for, assignments submitted and marks obtained, attendance for the practical courses etc. The application should be designed user-friendly.

Ans 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 datatypes 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<conio.h>

struct Student
{
 char name[20];
int enroll;
char address[40];
char program[10];
char course[10];
int num;
float marks;

}s[4];

in main()
{

int i ;
for(i  = 1;i <=4;i++)
{
printf("Enter Information : \n");
printf("Enter Name:");
gets(s[i].name)
printf("Enter Enrollment Number:\n");
scanf("%d",s[i].enroll);
printf("Enter Address:\n");
scanf("%d",s[i].address);
printf("Enter Programme:\n");
scanf("%d",s[i].program);
printf("Enter Course\n");
scanf("%d",s[i].course);
printf("Enter Contact Number\n:");
scanf("%d",s[i].num);
printf("Enter Marks:\n");
scanf("%d",s[i].marks);




for(i  = 1;i <=4;i++)
{
printf("Information Of Students\n");
printf("Name:");
puts(s[i].name);
printf(" Enrollment Number:\n");
printf("%d",s[i].enroll);
printf(" Address::");
printf("%d",s[i].address\n);
printf(" Programme:");
printf("%d",s[i].program);
printf("Course\n");
printf("%d",s[i].course);
printf("Contact Number\n:");
printf("%d",s[i].num);
printf("Marks\n:");
printf("%d",s[i].marks);


}

return 0;


}

Output:

Enter Information :
XYZ
Enter Enrollment Number:345653
Enter Address:Varanasi
Enter Programme:Mca
Enter Course:Mca Sem 1
Enter Contact Number:34567872
Enter Marks:89


Information Of Students
Name:XYZ
Enrollment Number:345653
Address:Varanasi
 Programme:Mca
Course:Mca Sem 1
Contact Number:34567872
Marks:89

Enter Information :
XYZ1
Enter Enrollment Number:34542
Enter Address:Gorakhpur
Enter Programme:Mca
Enter Course:Mca Sem 1
Enter Contact Number:1245673
Enter Marks:67


Information Of Students
Name:XYZ1
Enrollment Number:34542
Address:Gorakhpur
 Programme:Mca
Course:Mca Sem 1
Contact Number:1245673
Marks:67

Enter Information :
ABC
Enter Enrollment Number:345678
Enter Address:Varanasi
Enter Programme:Mca
Enter Course:Mca Sem 1
Enter Contact Number:34566872
Enter Marks:89


Information Of Students
Name:ABC
Enrollment Number:345678
Address:Varanasi
 Programme:Mca
Course:Mca Sem 1
Contact Number:34566872
Marks:89

Enter Information :
ZCF
Enter Enrollment Number:3145653
Enter Address:Varanasi
Enter Programme:Mca
Enter Course:Mca Sem 1
Enter Contact Number:345676872
Enter Marks:89


Information Of Students
Name:ZCF
Enrollment Number:3145653
Address:Varanasi
 Programme:Mca
Course:Mca Sem 1
Contact Number:345676872
Marks:89


          Section 2: Assembly Language Programming Lab



1.(a) Write a program in assembly language to find if two given strings are of equal length.

Ans 1 (a)
 Assembly language is a low-level programming language for a computer or other programmable device specific to a particular computer architecture in contrast to most high-level programming languages, which are generally portable across multiple systems. Assembly language is converted into executable machine code by a utility program referred to as an assembler like NASM, MASM, etc.


Advantages Of Assembly Language:
  • you can access machine-dependent registers and I/O
  • you can control the exact code behavior in critical sections that might otherwise involve deadlock between multiple software threads or hardware devices
  • you can break the conventions of your usual compiler, which might allow some optimizations (like temporarily breaking rules about memory allocation, threading, calling conventions, etc)
  • you can build interfaces between code fragments using incompatible conventions (e.g. produced by different compilers, or separated by a low-level interface)
  • you can get access to unusual programming modes of your processor (e.g. 16 bit mode to interface startup, firmware, or legacy code on Intel PCs)
  • you can produce reasonably fast code for tight loops to cope with a bad non-optimizing compiler (but then, there are free optimizing compilers available!)
  • you can produce hand-optimized code perfectly tuned for your particular hardware setup, though not to someone else's
  • you can write some code for your new language's optimizing compiler (that is something what very few ones will ever do, and even they not often)
  • i.e. you can be in complete control of your code






(b) Write a program in assembly language to find the factorial of any number (assume number is smaller than 10).

Ans(b).
In mathematics, the factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n. 
The factorial of a positive integer n is equal to 1*2*3*...n.







(c) Write a program in assembly language for reversing a four byte string.

Ans(c)
The variable length strings can have as many characters as required. Generally, we specify the length of the string by either of the two ways −

Explicitly storing string length
Using a sentinel character
We can store the string length explicitly by using the $ location counter symbol that represents the current value of the location counter. In the following example −

msg  db  'Hello, world!',0xa ;our dear string
len  equ  $ - msg            ;length of our dear string






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

Ans(d)

Arrays a kind of data structure that can store a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type.

NUMBERS DW  34,  45,  56,  67,  75, 89
The above definition declares an array of six words each initialized with the numbers 34, 45, 56, 67, 75, 89. This allocates 2x6 = 12 bytes of consecutive memory space. The symbolic address of the first number will be NUMBERS and that of the second number will be NUMBERS + 2 and so on.























1 comment: