In C language, In this project you are to create your own program, which has at
ID: 3717952 • Letter: I
Question
In C language,
In this project you are to create your own program, which has at least SIX of the following functions listed below..
1) 2D Arrays
2) File I/O
3) Strings
4) Pass by Reference
5) Structures
6) Command Line Arguments
7) Sorting
8) Recursion
9) Stack/Queue
10) Header Files
11) Linked Lists —*Pointers*
Proper use of each of the six functions is worth five points each.
Requirements—— This program shouldn’t be a straightforward implementation of the 6 functions used, but rather a somewhat useful, semi real-world program. Creativeness and originality of the program is included in the grade which is worth 5 points.
Proper documentation is also graded which includes comments throughout the code listing the functions used and documentation for how to use the program.
Six topics x 5 points ———— 30 points
Documentation ———— 5 points
Creativeness/Originality ——— 5 points
Explanation / Answer
/*
Learning six concepts of C with examples
*/
#include<string.h>
#include<process.h>
#include<stdio.h>
#include<conio.h>
void twoDarrayDemo();
void fileHandlingDemo();
void stringsDemo();
void structureDemo();
void passByRef(int *,int *);
void sortingDemo();
int main()
{
int a,b,choice;
printf("Six examples of six topics of C-programming language!! ");
printf("1..Example of Two Dimensional Array ");
printf("2..Example of File Handling ");
printf("3..Example of Strings ");
printf("4..Example of Structure ");
printf("5..Example of pass by reference ");
printf("6..Example of Sorting of array ");
printf("Enter your choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1:
twoDarrayDemo();
break;
case 2:
fileHandlingDemo();
break;
case 3:
stringsDemo();
break;
case 4:
structureDemo();
break;
case 5:
printf(" Enter values of a & b :");
scanf("%d%d",&a,&b);
passByRef(&a,&b);
break;
case 6:
sortingDemo();
break;
default:printf("Invalid Case or Selection!!");
}
getch();
}
//#Array : Transpose Matrix
void twoDarrayDemo()
{
int r,c;
int a[2][2],b[2][2];
printf("Enter eleements of two dimensional Array : ");
for(r=0;r<=1;r++)
{
for(c=0;c<=1;c++)
{
scanf("%d",&a[r][c]);
}
}
for(r=0;r<=1;r++)
{
for(c=0;c<=1;c++)
{
b[r][c]=a[c][r];
}
}
for(r=0;r<=1;r++)
{
for(c=0;c<=1;c++)
{
printf("%d",b[r][c]);
}
printf(" ");
}
}
//#File Handling in c:Reading Contents of A.txt
void fileHandlingDemo()
{
FILE *fp;
char ch;
fp=fopen("A.txt","r");
if(fp==NULL)
{
printf("File is not exist!!");
exit(0);
}
while(1)
{
ch=fgetc(fp);
if(ch==EOF)
{
break;
}
printf("%c",ch);
}
fclose(fp);
}
//#String functions in c:Demo System Defined functions
void stringsDemo()
{
int len;
char str[35];
printf(" Enter a string : ");
scanf("%s",str);
printf("Entered string is %s",str);
len=strlen(str);
printf("Length of given string is %s ",len);
printf("Entered string in uppercase : %s ",strupr(str));
}
//#Structure in c: Employee with its salary
void structureDemo()
{
struct Employee
{
int eno;
char enm[25];
float rate,month,salary;
};
struct Employee e1;
printf("Enter employee no & name : ");
scanf("%d%s",&e1.eno,e1.enm);
printf("Enter rate and month to get salary : ");
scanf("%f%f",&e1.rate,&e1.month);
printf("Employee No is %d ",e1.eno);
printf("Employee Name is %s ",e1.enm);
e1.salary=e1.rate*e1.month;
printf("Employee Salary is %f ",e1.salary);
}
//#Demo of call by reference
void passByRef(int *x,int *y)
{
printf(" Addition is %d ",(*x+*y));
}
//#Demo sorting of elements of array
void sortingDemo()
{
int a[5],i,temp,j;
printf("Enter elements of an array : ");
for(i=0;i<=4;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<=4;i++)
{
for(j=0;j<=4;j++)
{
if(a[i]<a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf(" ");
for(i=0;i<=4;i++)
{
printf("%d ",a[i]);
}
}