0% found this document useful (0 votes)
42 views3 pages

Fundamentals of Programming Lab Journal - Lab # 13: Objective

This lab document outlines exercises for students to complete involving structures in C++. The exercises involve declaring structures for points, dates, rectangles, and students. Students will declare variables and arrays of these structures, set structure field values using pointers, pass structures to functions by value and reference, and get user input to populate and display structure data. The exercises aim to cover structures, pointers to structures, arrays of structures, and passing structures to functions.

Uploaded by

Fadi Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views3 pages

Fundamentals of Programming Lab Journal - Lab # 13: Objective

This lab document outlines exercises for students to complete involving structures in C++. The exercises involve declaring structures for points, dates, rectangles, and students. Students will declare variables and arrays of these structures, set structure field values using pointers, pass structures to functions by value and reference, and get user input to populate and display structure data. The exercises aim to cover structures, pointers to structures, arrays of structures, and passing structures to functions.

Uploaded by

Fadi Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Lab 13

Fundamentals of Programming

Lab Journal - Lab # 13


Name: _________________________________

Enrollment #: _________________________________

Class: _________________________________

Objective

This lab will cover structures in C++, pointers to structures and arrays of structures. Student will
also do an exercise on passing structures to functions.

Tasks :

Write C++ code fragments for the following.

1. Declare a structure Point with x and y coordinates.

2. Declare a variable/object of type Point.

3. Declare a variable of type Point, a pointer to Point and an array of 10 Points. Assign the
address of the variable to the pointer.

Point p;
Point *pj;
Point px[10];

Pj=&p;

Fundamentals of Programming Page 1


Lab 13

4. Using pointer variable set the value of x-coordinate in structure Point to 5 and that of
y-coordinate to 10.

5. Declare a structure Date. Declare another structure Project with fields: ID, startDate
and endDate. (Use nested structures).

6. How would you call the function void displayDate(Date) where Date is a structure.

Exercise 1

Write a program with a structure Rectangle having fields length and width. Get
user input for the fields and pass it to a function display(Rectangle) to output the
length and width of the rectangle.

Now change this program to add the function getInput(Rectangle &) and get the
user input within the function. Change the function display(Rectangle) to
display(Rectangle *) and use the pointer variable to display the length and width
of the rectangle.

Fundamentals of Programming Page 2


Lab 13

Exercise 2

i. Declare a structure Date with three integer fi elds day, month


and year.
ii. Declare a structure Student with fi elds ID (int), gpa (float)
and dateOfBirth (Date).
iii. In the main() function, declare an array of 10 Students.
iv. Defi ne a function getInput() and pass this array to the
function. The function should prompt user to enter values for
name, gpa and date of birth of the 10 students. (Use a for
loop)
v. Defi ne a function displayRecords(), which accepts the array
of Students as argument and displays the data for students.
vi. Call the functions getInput() and displayRecords() from the
main.

Do Exercises 1 and 2 and get them checked by your instructor.

S No. Exercise Checked By:


1. Exercise 1
2. Exercise 2

+++++++++++++++++++++++++

Fundamentals of Programming Page 3

You might also like