Showing posts with label structure. Show all posts
Showing posts with label structure. Show all posts

Saturday, May 21, 2011

C Program to implement telephone billing System

/*Code to accept 10 telephone customers’ data into a structure
object.
The fields are:
Customer name
Telephone number
Units to be billed
Calculate Bill Amount, which is Rent of Rs. 250 plus Re 0.80 for each
unit. Prepare the Bill and print it.*/


int main()
{
int n,i;
struct bill
{
char name[20];
int num;
int units;
}a[50];


printf("\nEnter the no of customers");
scanf("%d",&n);
for(i=0;i {
printf("\nEnter the customer's name");
scanf("%s",&a[i].name);
printf("\nEnter the customer's number");
scanf("%d",&a[i].num);
printf("\nEnter the no of units");
scanf("%d",&a[i].units);
}
for(i=0;i {
printf("\nname %s",a[i].name);
printf("\nnumber %d",a[i].num);
printf("\nBill is Rs %f",((a[i].units)*0.8)+250);



}
system("pause");
return 0;
}

C program to explain use of Structures

/*Code a program to do the following with a structure:
a. Declare the structure with the following members:
Name char 20
Age int
Gender char 1
Marks float
b. Initialize the members with your values.
c. Print the memory space occupied by the structure object.
d. Print the formatted structure data.*/

int main()
{
int n,i;
struct marks
{
char name[20];
int age;
char gen;
float marks;
}a[50];


printf("\nEnter the no of entries");
scanf("%d",&n);
for(i=0;i {
printf("\nEnter the name");
scanf("%s",&a[i].name);
printf("\nEnter the age");
scanf("%d",&a[i].age);
printf("\nEnter the gender");
scanf("%c",&a[i].gen);
printf("\nEnter the no of marks");
scanf("%f",&a[i].marks);
}
for(i=0;i {
printf("size of object a%d is %d",i,sizeof(a[i]));
}
for(i=0;i {
printf("\nname %s",a[i].name);
printf("\nage %d",a[i].age);
printf("\n%c",a[i].gen);
printf("\n%f",a[i].marks);
}
system("pause");
return 0;
}