Professional Documents
Culture Documents
Index Page With 18-22 Programs
Index Page With 18-22 Programs
INDEX
};
/* prints payslip for the requested employee */
void printSalary(struct employee e1) {
printf("Salary Slip of %s:\n", e1.name);
printf("Employee ID: %d\n", e1.empId);
printf("Basic Salary: %d\n", e1.basic);
printf("House Rent Allowance: %d\n", e1.hra);
printf("Dearness Allowance: %d\n", e1.da);
printf("Medical Allowance: %d\n", e1.ma);
printf("Gross Salary: %.2f Rupees\n", e1.gross);
printf("\nDeductions: \n");
printf("Provident fund: %d\n", e1.pf);
printf("Insurance: %d\n", e1.insurance);
printf("\nNet Salary: %.2f Rupees\n\n", e1.net);
return;
}
int main() {
int i, ch, num, flag, empID;
struct employee *e1;
/* get the number of employees from the user */
printf("Enter the number of employees:");
scanf("%d", &num);
/* dynamically allocate memory to store employee salary details */
e1 = (struct employee *)malloc(sizeof(struct employee) * num);
/* get the employee salary details from the customer */
printf("Enter your input for every employee:\n");
for (i = 0; i <num; i++) {
printf("Employee ID:");
scanf("%d", &(e1[i].empId));
getchar();
printf("Employee Name:");
fgets(e1[i].name, 32, stdin);
e1[i].name[strlen(e1[i].name) - 1] = '\0';
printf("Basic Salary, HRA:");
scanf("%d%d", &(e1[i].basic), &(e1[i].hra));
printf("DA, Medical Allowance:");
scanf("%d%d", &(e1[i].da), &(e1[i].ma));
printf("PF and Insurance:");
scanf("%d%d", &(e1[i].pf), &(e1[i].insurance));
printf("\n");
}
/* gross and net salary calculation */
for (i = 0; i <num; i++) {
e1[i].gross = e1[i].basic +
(e1[i].hra * e1[i].basic) / 100 +
(e1[i].da * e1[i].basic) / 100 +
(e1[i].ma * e1[i].basic) / 100;
e1[i].net = e1[i].gross - (e1[i].pf + e1[i].insurance);
}
/* printing payslip for the given employee ID */
while (1) {
printf("Enter employee ID to get payslip:");
scanf("%d", &empID);
flag = 0;
for (i = 0; i <num; i++) {
if (empID == e1[i].empId) {
printSalary(e1[i]);
flag = 1;
}
}
if (!flag) {
printf("No Record Found!!\n");
}
printf("Do You Want To Continue(1/0):");
scanf("%d", &ch);
if (!ch) {
break;
}
} return 0; }
OUTPUT:
#include<stdio.h>
#include<conio.h>
struct student
{
int sub1;
int sub2;
int sub3;
int sub4;
int sub5;
};
void main()
{
struct student s[10];
int i,total=0;
clrscr();
for(i=0;i<=2;i++)
{
printf("\nEnter marks in 5 subjects:");
scanf("%d%d%d%d
%d",&s[i].sub1,&s[i].sub2,&s[i].sub3,&s[i].sub4,&s[i].sub5);
total=s[i].sub1+s[i].sub2+s[i].sub3+s[i].sub4+s[i].sub5;
printf("\nTotal marks of s[%d] student=%d",i,total);
}
getch();
}
OUTPUT:
/*Telephone directory*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct Phonebook_Contacts
{
char FirstName[20];
char LastName[20];
char PhoneNumber[20];
} phone;
void AddEntry(phone * );
void DeleteEntry(phone * );
void PrintEntry(phone * );
void SearchForNumber(phone * );
int counter = 0;
char FileName[256];
FILE *pRead;
FILE *pWrite;
void main (void)
{
phone *phonebook;
int iSelection=0;
phonebook = (phone*) malloc(sizeof(phone)*100);
//int iSelection = 0;
if (phonebook == NULL)
{
printf("Out of Memory. The program will now exit");
}
else {}
do
{
printf("\n\t\t\tPhonebook Menu");
printf("\n\n\t(1)\tAdd Friend");
printf("\n\t(2)\tDelete Friend");
printf("\n\t(3)\tDisplay Phonebook Entries");
printf("\n\t(4)\tSearch for Phone Number");
printf("\n\t(5)\tExit Phonebook");
printf("\n\nWhat would you like to do? ");
scanf("%d", &iSelection);
if (iSelection == 1)
{
AddEntry(phonebook);
}
if (iSelection == 2)
{
DeleteEntry(phonebook);
}
if (iSelection == 3)
{
PrintEntry(phonebook);
}
if (iSelection == 4)
{
SearchForNumber(phonebook);
}
if (iSelection == 5)
{
printf("\nYou have chosen to exit the Phonebook.\n");
getch();
}
} while (iSelection<= 4);
}
void AddEntry (phone * phonebook)
{
pWrite = fopen("phonebook_contacts.dat", "a");
if ( pWrite == NULL )
{
perror("The following error occurred ");
exit(EXIT_FAILURE);
}
else
{
counter++;
realloc(phonebook, sizeof(phone));
printf("\nFirst Name: ");
scanf("%s", phonebook[counter-1].FirstName);
printf("Last Name: ");
scanf("%s", phonebook[counter-1].LastName);
printf("Phone Number (XXX-XXX-XXXX): ");
scanf("%s", phonebook[counter-1].PhoneNumber);
printf("\n\tFriend successfully added to Phonebook\n");
--counter;
return;
}
}
}
printf("That contact was not found, please try again.");
}
void PrintEntry (phone * phonebook)
{
int x = 0;
printf("\nPhonebook Entries:\n\n ");
pRead = fopen("phonebook_contacts.dat", "r");
if (pRead == NULL)
{
perror("The following error occurred: ");
exit(EXIT_FAILURE);
}
else
{
for( x = 0; x < counter; x++)
{
printf("\n(%d)\n", x+1);
printf("Name: %s %s\n", phonebook[x].FirstName, phonebook[x].LastName);
printf("Number: %s\n", phonebook[x].PhoneNumber);
}
}
fclose(pRead);
}
void SearchForNumber (phone * phonebook)
{
int x = 0;
char TempFirstName[20];
char TempLastName[20];
printf("\nPlease type the name of the friend you wish to find a number for.");
printf("\n\nFirst Name: ");
scanf("%s", TempFirstName);
printf("Last Name: ");
scanf("%s", TempLastName);
for (x = 0; x < counter; x++)
{
if (strcmp(TempFirstName, phonebook[x].FirstName) == 0)
{
if (strcmp(TempLastName, phonebook[x].LastName) == 0)
{
printf("\n%s %s's phone number is %s\n", phonebook[x].FirstName,
phonebook[x].LastName, phonebook[x].PhoneNumber);
}
}
}
}
OUTPUT:
s[a].no=i;
printf("\n Enter your name:");
scanf("%s",s[a].name);
printf("\n your deposit is minimum Rs.500");
s[a].dep=500;
a++;i++;
}
void deposit()
{
int no,b=0,m=0;float aa;
printf("\n ******************");
printf("\n CASH DEPOSIT");
printf("\n ******************");
printf("\n Enter your account number:");
scanf("%d",&no);
for(b=0;b<i;b++)
{
if(s[b].no==no)
m=b;
}
if(s[m].no==no)
{
printf("\n Account number:%d",s[m].no);
printf("\n Name:%s",s[m].name);
printf("\n deposit:%f",s[m].dep);
printf("\n Deposited amount:");
scanf("%f",&aa);
s[m].dep+=aa;
printf("\n The balance in account is :%f",s[m].dep);
}
else
{
printf("\n Account Number is Invalid");
}
}
void withdraw()
{
int no,b=0,m=0;
float aa;
printf("\n ***********************");
printf("\n cash withdraw");
printf("\n ***********************");
printf("\n Enter your account number:");
scanf("%d",&no);
for(b=0;b<i;b++)
{
if(s[b].no==no)
m=b;
}
if(s[m].no==no)
{
printf("\n account number:%d",s[m].no);
printf("\n Name:%s",s[m].name);
printf("\n Deposit:%f",s[m].dep);
OUTPUT:
int c;
printf("availability cheking");
printf("\n1.first class\n2.second class\n3.thired class\n");
printf("enter the option");
scanf("%d",&c);
switch(c)
{
case 1:if(first>0)
{
printf("seat available\n");
first--;
}
else
{
printf("seat not available");
}
break;
case 2: if(second>0)
{
printf("seat available\n");
second--;
}
else
{
printf("seat not available");
}
break;
case 3:if(thired>0)
{
printf("seat available\n");
thired--;
}
else
{
printf("seat not available");
}
break;
default:
break;
}
}
void cancel()
{
int c;
printf("cancel\n");
printf("which class you want to cancel");
printf("\n1.first class\n2.second class\n3.thired class\n");
printf("enter the option");
scanf("%d",c);
switch(c)
{
case 1:
first++;
break;
case 2:
second++;
break;
case 3:
thired++;
break;
default:
break;
}
printf("ticket is canceled");
}
void chart()
{
int c;
for(c=0;c<i;c++)
{
printf("\n Ticket No\t Name");
printf("%d\t%s\n",s[c].ticketno,s[c].name);
}
}
main()
{
int n;
clrscr();
printf("welcome to railway ticket reservation\n");
while(1) {
printf("1.booking\n2.availability cheking\n3.cancel\n4.Chart \n5. Exit\nenter
your option:");
scanf("%d",&n);
switch(n)
{
case 1: booking();
break;
case 2: availability();
break;
case 3: cancel();
break;
case 4:
chart();
break;
case 5:
printf("\n Thank you visit again!");
getch();
exit(0);
default:
break;
}
}
getch();
}
OUTPUT: