Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Topic: Structures

Aim: To get familiar with the declaration and use of structure and also pass the structure as an
argument to the function.

Task 1
Define a structure Ticket that holds data items of a carnival which includes: name of the carnival,
total amount of tickets, price per ticket, total tickets sold and total sales. The total sale is based
on the price per ticket and total tickets sold. Input the data into structure type variable and print
it on the screen.

Task 2
Create a structure student that stores all data related to student. It include name, registration
number, address, contact number, student marks etc. Implement the concept of nested structure
for address. Declare structure type variable, input data from the user and display it. Take record
of at least 2 students.
SOLUTION:
#include<iostream.h>
#include<conio.h>
void main(void)
{
clrscr();
cout<<"Bakhtawar javed"<<endl;
struct adress
{
char adress[100];
};
struct STUDENT
{
char nameofstd[50];
int contactno;
long int regno;
int marks;
adress a;
};
STUDENT std[3]={"",0,0,0,""};
for(int i=0;i<=2;i++)
{
cout<<"Enter name of student"<<endl;
cin>>std[i].nameofstd;
cout<<"Enter contact no. of student"<<endl;
cin>>std[i].contactno;
cout<<"Enter Registration No."<<endl;
cin>>std[i].regno;
cout<<"Enter marks of student"<<endl;
cin>>std[i].marks;
cout<<"Enter adress of student"<<endl;
cin>>std[i].a.adress;
}
cout<<endl;
getche();
}
OUTPUT:

Bakhtawar javed
Enter name of student
bakhtawar
Enter contact no. of student
123
Enter marks of student
95
Enter address of student
rwp
Enter name of student
riaheen
Enter contact no. of student
456
Enter marks of student
96
Enter address of student
tts
Enter name of student
fatima
Enter contact no. of student
678
Enter marks of student
78
Enter address of student
isb

Task 3
Define a structure called “tollbooth”. The two data items are a type unsigned int to hold the total
number of cars, and a type double to hold the total amount of money collected. In main,
initializes both of these to 0. A function called PayingCar () increment the total car and adds 0.50
to the cash total. Another function nopayCar () increments the car total but adds nothing to the
cash total. Finally a member function called display (), displays the two totals.
Write a program to test this functionality. This program should allow the user to push one key to
count a paying car and another to count a non-paying car. Pushing the ESC key should cause the
program to print out the total cars and total cash and then exits.
Task 4
Create a structure to specify data of customers in a bank. The data to be stored is: Account
number, Name, Balance in account. Assume maximum of 200 customers in the bank.
(a) Write a function to print the account number and name of each customer with balance
below Rs 100.
(b) If a customer requests for withdrawal or deposit, it is given in the form: Account number,
amount, code (1 for deposit, 0 for withdrawal).
(c) Write a function deposit() that adds money to the balance of account if customers selects
deposit option
(d) If customer selects withdrawal option, then a function withdrawal () first checks that
sufficient balance is available for withdrawal or not. If available, then deduct money from
the balance and issue message “Withdraw Successfully”, otherwise display message
“Insufficient Balance”.

You might also like