Click here to Download Assignment#2 | Click here to Download Cover Page
ONLINE PREVIEW:
STATEMENT: A PROGRAM TO MANIPULATE (INPUT, PROCESS, DISPLAY) MARKS RECORD OF STUDENT USING STRUCTURE
ALGORITHM:
Step1 | Start |
Step2 | Set a constant x as 3 |
Step3 | Initialize ask=0 |
Step4 | Display "\nWhat operation would you like to perform?" "\n1. Input Data" "\n2. Display Data" "\n3. Process Record" "\n4. EXIT\n" “\nYour option:” |
Step5 | Ask user for input as variable ask |
Step6 | Is ask=1? |
YES | Goto Step7 |
NO | Goto Step18 |
Step7 | Display "\n\nYou Want to:\n" "\n A.Input all" "\n notA.Input specific data?" "\n Your option:" |
Step8 | Ask user for option as askchar |
Step9 | Is askchar=’A’ |
YES | Goto Step10 |
NO | Goto Step15 |
Step10 | Set i=0 |
Step11 | Is i<x? |
YES | Goto step12 |
NO | Goto step17 |
Step12 | Call userdefined function ipdata(i) |
Step13 | Increase the value of i by 1` |
Step14 | Goto Step11 |
Step15 | Ask user for input as any number from 1 to ‘x’ |
Step16 | Call userdefined function ipdata(i-1) |
Step17 | Goto Step3 |
Step18 | Is ask=2? |
YES | Goto Step19 |
NO | Goto Step21 |
Step19 | Call userdefined function showdata() |
Step20 | Goto Step3 |
Step21 | Is ask=3? |
YES | Goto Step22 |
NO | Goto Step24 |
Step22 | Call userdefined function processrey() |
Step23 | Goto Step3 |
Step24 | Is ask=4? |
YES | Goto Step27 |
NO | Goto Step25 |
Step25 | Display “n INVALID ENTRY! Please enter again!!\n\n” |
Step26 | Goto Step3 |
Step27 | Stop |
Step1 | Start of userdefined function ipdata(int i) |
Step2 | Display “Data Entry for Student no %d’,i+1 |
Step3 | Ask user for fname and lname of student |
Step4 | Ask user for name of course |
Step5 | Ask user for marks in Physics, Mathematics, it, C, and Stat |
Step6 | Stop |
Step1 | Start of userdefined function showdata() |
Step2 | Display “\nName\t\tCourse\tTotal\tPercent\n\n” |
Step3 | Set i=0 |
Step4 | Is i<x? |
YES | Goto Step5 |
NO | Goto Step9 |
Step5 | Calculate tot=profile[i].sub.phy+profile[i].sub.math+profile[i].sub.it+profile[i].sub.c+profile[i].sub.stat |
Step6 | Display profile[i]fname, profile[i]lname, tot, and tot/5 with tab space in between |
Step7 | Increase the value of I by 1 |
Step8 | Goto Step4 |
Step9 | Stop |
Step1 | Start of userdefined function processrey() |
Step2 | Initialize sum=0 and i=0 |
Step3 | Is i<x? |
YES | Goto Step4 |
NO | Goto Step7 |
Step4 | Calculate sum=sum+profile[i].sub.phy+profile[i].sub.math+profile[i].sub.it+profile[i].sub.c+profile[i].sub.stat |
Step5 | Increase the value of i by 1 |
Step6 | Goto Step3 |
Step7 | Display total of all students as sum |
Step8 | Stop |
SOURCE CODE:
#include <stdio.h> #include <conio.h> #include <ctype.h> #include <process.h> #define x 3 typedef struct{ int phy; int math; int it; int c; int stat; }rec; rec sub; typedef struct{ char fname[20]; char lname[20]; char cname[20]; rec sub; }rec2; rec2 profile[x]; void main() { int ask=0,i; char askchar; clrscr(); void ipdata(int i); void showdata(void); void processrey(void); asker: printf("\nWhat operation would you like to perform?" "\n1. Input Data" "\n2. Display Data" "\n3. Process Record" "\n4. EXIT\n"); printf("Your option:"); scanf("%d",&ask); switch (ask) { case 1: printf("\n\nYou Want to:\n" "\n A.Input all" "\n notA.Input specific data?" "\n Your option:"); askchar=toupper(getche()); if (askchar=='A') { for(i=0;i<x;i++) { ipdata(i); } } else { printf("\n\nInput for Data number(choose 1 to %d):",x); scanf("%d",&i); ipdata(i-1); } break; case 2: showdata(); break; case 3: processrey(); break; case 4: abort(); default: printf("\n INVALID ENTRY! Please enter again!!\n\n"); } goto asker; } void ipdata(int i) { //INPUT BELOW: printf("\n\nDATA ENTRY FOR STUDENT NO. %d\n",i+1); flushall(); printf("\nEnter fname of student: "); scanf("%[^\n]",profile[i].fname); flushall(); printf("\nEnter lname of student: "); scanf("%[^\n]",profile[i].lname); flushall(); printf("\nEnter name of course: "); scanf("%[^\n]",profile[i].cname); flushall(); printf("\nEnter marks in Phy: ");scanf("%d",&profile[i].sub.phy); printf("\nEnter marks in Math: ");scanf("%d",&profile[i].sub.math); printf("\nEnter marks in IT: ");scanf("%d",&profile[i].sub.it); printf("\nEnter marks in C: ");scanf("%d",&profile[i].sub.c); printf("\nEnter marks in Stat: ");scanf("%d",&profile[i].sub.stat); } void showdata() { int i; printf("\n\nName \t\tCourse\tTotal\tPercent\n\n"); for(i=0;i<x;i++) { int tot; tot=profile[i].sub.phy+profile[i].sub.math+profile[i].sub.it+profile[i].sub.c+profile[i].sub.stat; printf("%s %s\t%s\t%d\t%f\n",profile[i].fname,profile[i].lname,profile[i].cname,tot,(float)tot/5); } } void processrey() { void showdata(); int i,sum=0; showdata(); for (i=0;i<x;i++) { sum=sum+profile[i].sub.phy+profile[i].sub.math+profile[i].sub.it+profile[i].sub.c+profile[i].sub.stat; } printf("\nTotal of all students is %d\n",sum); } |
OUTPUT SCREEN:
RESULT:
The result of this program is a comprehensive data in tabulated form obtained with the help of raw data provided by the user.
CONCLUSION:
The use of structures and structures within structures can be implemented to easily categorize input variables and manipulate those values by passing structures within functions.
STATEMENT:A PROGRAM TO MERGE TWO ARRAYS USING FUNCTION
ALGORITHM:
Step1 | Start |
Step2 | Set constant x=5 |
Step3 | Set constant y=6 |
Step4 | Declare Global array c[x+y] |
Step5 | Initialize a[x]={1,2,3,4,5} and b[y]={6,7,8,9,10,11} |
Step6 | Call userdefined function mergex(a,b) |
Step7 | Set i=0 |
Step8 | Is i<x+y? |
YES | Goto Step9 |
NO | Goto Step12 |
Step9 | Display c[i] |
Step10 | Increase the value of i by 1 |
Step11 | Goto step8 |
Step12 | Stop |
Step1 | Start of userdefined function mergex(int a[], int b[]) |
Step2 | Initialize k=0 and i=0 |
Step3 | Is i<x? |
YES | Goto step4 |
NO | Goto Step8 |
Step4 | Set c[k]=a[i] |
Step5 | Increase the value of k by 1 |
Step6 | Increase the value of i by 1 |
Step7 | Goto Step3 |
Step8 | Set i=0 |
Step9 | Is i<y? |
YES | Goto step10 |
NO | Goto Step14 |
Step10 | Set c[k]=b[i] |
Step11 | Increase the value of k by 1 |
Step12 | Increase the value of i by 1 |
Step13 | Goto Step9 |
Step14 | Stop |
SOURCE CODE:
#include <stdio.h> |
#include <conio.h> |
#define x 5 |
#define y 6 |
int c[x+y]; |
void main() |
{ |
clrscr(); |
void mergex(int a[],int b[]); |
int a[x]={1,2,3,4,5},b[y]={6,7,8,9,10,11},i; |
mergex(a,b); |
printf("Merged array:\n\n"); |
for(i=0;i<x+y;i++) |
{ |
printf("%d ",c[i]); |
} |
getch(); |
} |
void mergex(int a[],int b[]) |
{ |
int i,k=0; |
for(i=0;i<x;i++) |
{ |
c[k]=a[i]; |
k++; |
} |
for(i=0;i<y;i++) |
{ |
c[k]=b[i]; |
k++; |
} |
} |
OUTPUT SCREEN:
RESULT:
The result of this program is the combined contents of two arrays, a[] and b[], which was stored in a third array c[] whose array size was the combined array size of the former two arrays.
CONCLUSION:
The objective of this program, to show how data are stored in arrays, was completed by fulfilling a secondary objective that required the programmer to be able to merge arrays. In any method used to solve this problem, a particular space in destination array is always given to oneparticular value in the target array. i.e. the values of arrays a[] and b[] are consecutively and successively stored inside the array c[].
The objective of this program, to show how data are stored in arrays, was completed by fulfilling a secondary objective that required the programmer to be able to merge arrays. In any method used to solve this problem, a particular space in destination array is always given to oneparticular value in the target array. i.e. the values of arrays a[] and b[] are consecutively and successively stored inside the array c[].
COMMENTS:
Blogger Comments:
Emoticon Emoticon