Slip 27
Q1. Write a program to count the occurrences of vowel from a input string. [15 Marks]
#include <stdio.h>
int main()
{
char line[150];
int i, vowels;
vowels = 0;
printf("Enter a line of string: ");
scanf("%[^\n]", line);
for(i=0; line[i]!='\0'; ++i)
{ if(line[i]=='a' || line[i]=='e' || line[i]=='i' ||
line[i]=='o' || line[i]=='u' || line[i]=='A' ||
line[i]=='E' || line[i]=='I' || line[i]=='O' ||
line[i]=='U')
{
++vowels;
}
}
printf("Vowels: %d",vowels);
return 0;
}
Q2. Create a structure Item (Ino, Iname, Price). Accept details of n Items and write a
menu driven program to perform the following operations options. [25 Marks]
1. Display all Items having price > 800
2. Display Item record with Ino=2
#include<stdio.h>
#include<stdlib.h>
struct details
{
char name[30];
int eid;
int salary;
}emp[5];
void emp_search(int r)
{
int id,i;
printf("\nEnter Employee-Id to be Searched : ");
scanf("%d",&id);
printf("----------------------------------------\n");
for(i=0;i<r;i++)
{
if(emp[i].eid==id)
{
printf("Employee Id : %d",emp[i].eid);
printf("\nName : %s",emp[i].name);
printf("\nSalary : %d\n",emp[i].salary);
}
}
}
void display(int r)
{
int i;
printf("\nList of All Employees:\n");
printf("-------------------------------\n");
printf("Emp-Id\tEmp-Name Salary\n");
printf("--------------------------------\n");
for(i=0;i<r;i++)
{
printf("%d\t%s\t %d\n",emp[i].eid,emp[i].name,emp[i].salary);
}
}
void greater(int r)
{
int i;
printf("\nDetails of Employee Whose Salary > 10000\n");
printf("------------------------------------------------");
for(i=0;i<r;i++)
{
if(emp[i].salary>800)
{
printf("\n Employee Name : %s",emp[i].name);
printf("\n Employee-Id : %d",emp[i].eid);
printf("\n Salary : %d\n",emp[i].salary);
}
}
}
int main()
{
int n,i,ch;
printf("/*How Many Employee Record You Want to Add*/\n\nEnter Limit : ");
scanf("\n %d",&n);
for(i=0;i<n;i++)
{
printf("-----------------------------------------");
printf("\n\tEnter Details of Employee-%d",i+1);
printf("\n-----------------------------------------");
printf("\nName of Employee : ");
scanf("%s",emp[i].name);
printf("Employee-Id : ");
scanf("%d",&emp[i].eid);
printf("Salary : ");
scanf("%d",&emp[i].salary);
}
while(1)
{
printf("-----------------------------------------\n");
printf("\t\tMenu\n");
printf("-----------------------------------------");
printf("\n 1:Search Employee by E-ID");
printf("\n 2:List of All Employee");
printf("\n 3:Display Employee Name whose Salary > 800 ");
printf("\n 4:Exit");
printf("\n----------------------------------------\n");
printf("Enter Your Choice : ");
scanf("\n %d",&ch);
switch(ch)
{
case 1: emp_search(n);
break;
case 2: display(n);
break;
case 3: greater(n);
break;
case 4: exit(0);
}
}
return 0;
}
#include<stdlib.h>
struct details
{
char name[30];
int eid;
int salary;
}emp[5];
void emp_search(int r)
{
int id,i;
printf("\nEnter Employee-Id to be Searched : ");
scanf("%d",&id);
printf("----------------------------------------\n");
for(i=0;i<r;i++)
{
if(emp[i].eid==id)
{
printf("Employee Id : %d",emp[i].eid);
printf("\nName : %s",emp[i].name);
printf("\nSalary : %d\n",emp[i].salary);
}
}
}
void display(int r)
{
int i;
printf("\nList of All Employees:\n");
printf("-------------------------------\n");
printf("Emp-Id\tEmp-Name Salary\n");
printf("--------------------------------\n");
for(i=0;i<r;i++)
{
printf("%d\t%s\t %d\n",emp[i].eid,emp[i].name,emp[i].salary);
}
}
void greater(int r)
{
int i;
printf("\nDetails of Employee Whose Salary > 10000\n");
printf("------------------------------------------------");
for(i=0;i<r;i++)
{
if(emp[i].salary>800)
{
printf("\n Employee Name : %s",emp[i].name);
printf("\n Employee-Id : %d",emp[i].eid);
printf("\n Salary : %d\n",emp[i].salary);
}
}
}
int main()
{
int n,i,ch;
printf("/*How Many Employee Record You Want to Add*/\n\nEnter Limit : ");
scanf("\n %d",&n);
for(i=0;i<n;i++)
{
printf("-----------------------------------------");
printf("\n\tEnter Details of Employee-%d",i+1);
printf("\n-----------------------------------------");
printf("\nName of Employee : ");
scanf("%s",emp[i].name);
printf("Employee-Id : ");
scanf("%d",&emp[i].eid);
printf("Salary : ");
scanf("%d",&emp[i].salary);
}
while(1)
{
printf("-----------------------------------------\n");
printf("\t\tMenu\n");
printf("-----------------------------------------");
printf("\n 1:Search Employee by E-ID");
printf("\n 2:List of All Employee");
printf("\n 3:Display Employee Name whose Salary > 800 ");
printf("\n 4:Exit");
printf("\n----------------------------------------\n");
printf("Enter Your Choice : ");
scanf("\n %d",&ch);
switch(ch)
{
case 1: emp_search(n);
break;
case 2: display(n);
break;
case 3: greater(n);
break;
case 4: exit(0);
}
}
return 0;
}
No comments:
Post a Comment