0% found this document useful (0 votes)
233 views7 pages

Lab Report 10

1) The document describes three programming tasks completed by a student. The first task involves creating a structure to store student data and printing it. The second task involves creating an array of structures to store multiple students' data and defining functions to retrieve specific students. The third task compares two dates entered by the user using a date structure. 2) For each task, the student provides the source code and a screenshot of the output. The code demonstrates the use of structures, arrays, and functions to organize and retrieve data in C++. 3) The tasks allow the student to practice common programming concepts like defining structures, arrays, and functions while handling user input, comparing values, and printing output.

Uploaded by

salmo
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)
233 views7 pages

Lab Report 10

1) The document describes three programming tasks completed by a student. The first task involves creating a structure to store student data and printing it. The second task involves creating an array of structures to store multiple students' data and defining functions to retrieve specific students. The third task compares two dates entered by the user using a date structure. 2) For each task, the student provides the source code and a screenshot of the output. The code demonstrates the use of structures, arrays, and functions to organize and retrieve data in C++. 3) The tasks allow the student to practice common programming concepts like defining structures, arrays, and functions while handling user input, comparing values, and printing output.

Uploaded by

salmo
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/ 7

Shaheed Zulfikar Ali Bhutto Institute of Science & Technology 9

COMPUTER SCIENCE DEPARTMENT

Fundamentals of
Programming
(LAB)
Lab Report # 13

Submitted To: Muhammad Touqeer Ali

Student Name: Salman Karim

Reg. Number: 2012185

BSCS-1B
PROGRAMMING FUNDAMENTAL (PF) LAB
SZABIST-ISB
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology 9

Task (01):
Write a program to store and print the roll no., name , age and marks of a
student using structures.

Source Code:
1. #include<iostream>  
2. #include<string>  
3. using namespace std;  
4. struct student  
5. {  
6.     int rollno;  
7.     string name;  
8.     int age;  
9.     int marks;  
10. };  
11. int main()  
12. {  
13.     student std;  
14.       
15.     cout<<"Enter your Roll No: ";  
16.     cin>>std.rollno;  
17.     cout<<"Enter your Name: ";  
18.     cin.seekg(0);  
19.     getline(cin,std.name);  
20.     cout<<"Enter your Age: ";  
21.     cin>>std.age;  
22.     cout<<"Enter your Marks: ";  
23.     cin>>std.marks;  
24.       
25.     cout<<"\n\nYour Roll No: "<<std.rollno;  
26.     cout<<"\nYour Name: "<<std.name;  
27.     cout<<"\nYour Age: "<<std.age;  
28.     cout<<"\nYour Marks: "<<std.marks;  
29.       
30.     return 0;  
31. }  

Screenshot of Output:

BSCS-1B
PROGRAMMING FUNDAMENTAL (PF) LAB
SZABIST-ISB
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology 9

Task (02):
Write a structure to store the roll no., name, age (between 11 to 14) and
address of students (more than 10). Store the information of the students.
 Write a function to print the names of all the students having age 14.
 Write another function to print the names of all the students having even
roll number
 Write another function to display the details of the student whose roll no
is given (i.e. roll no. entered by the user).

Source Code:
1. #include <iostream>  
2. #include <string>
3. using namespace std;  
4. struct student {  
5.     int rollNo;  
6.     int age;  
7.     string name;  
8.     string address;  
9. };  
10.   

BSCS-1B
PROGRAMMING FUNDAMENTAL (PF) LAB
SZABIST-ISB
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology 9

11. void getAge(student[]);  
12. void inputDetails(student[]);  
13. void evenRollno(student[]);  
14. void rollNoCheck(student[]);  
15.   
16. int main() {  
17.     student stds[3];  
18.     inputDetails(stds);  
19. getAge(stds);  
20.     evenRollno(stds);  
21.     rollNoCheck(stds);  
22. }  
23.   
24. void inputDetails(student s[]) {  
25.     for (int i =0; i<3; i++) {  
26.         cout << "Enter a name for student [" << i + 1 << "]: ";  
27.         cin >> s[i].name;  
28.         cout << "Enter an age for student [" << i + 1 << "]: ";  
29.         cin >> s[i].age;   
30.         cout << "Enter a rollNo for student [" << i + 1 << "]: ";  
31.         cin >> s[i].rollNo;   
32.         cout << "Enter an adress for student [" << i + 1 << "]: ";  
33.         cin >> s[i].address;  
34.     }  
35. }  
36.   
37. void getAge(student s[]) {  
38.     cout << "Students who are 14: ";  
39.     for (int i =0; i<4; i++) {  
40.         if(s[i].age == 14) {  
41.             cout << s[i].name << ", ";  
42.         }  
43.     }  
44.     cout << endl;  
45. }  
46.   
47. void evenRollno(student s[]) {  
48.     cout << "Students whose roll no's are even: ";  
49.     for (int i =0; i<4; i++) {  
50.         if(s[i].rollNo % 2 == 0) {  
51.             cout << s[i].name << ", ";  
52.         }  
53.     }  
54. cout << endl;  
55. }  
56.   
57. void rollNoCheck(student s[]) {  
58.     int n;  
59.     cout << "Enter a roll no: ";  
60.     cin >> n;  
61.     for (int i =0; i<4; i++) {  

BSCS-1B
PROGRAMMING FUNDAMENTAL (PF) LAB
SZABIST-ISB
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology 9

62.         if(s[i].rollNo == n) {  
63.             cout << "\nStudent whose roll no you just entered: "<<s[i].name;  
64.         }  
65.     }  
66.     cout << endl;  
67. }  

Screenshot of Output:

Task (03):
Write a program to compare two dates entered by user. Make a structure
named Date to store the elements day, month and year to store the dates. If the

BSCS-1B
PROGRAMMING FUNDAMENTAL (PF) LAB
SZABIST-ISB
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology 9

dates are equal, display "Dates are equal" otherwise display "Dates are not
equal".

Source Code:
1. #include<iostream>  
2. using namespace std;  
3. struct date {  
4.     int day;  
5.     int month;  
6.     int year;  
7. };  
8.   
9. void compare(date d1, date d2) {  
10.     if(d1.day == d2.day && d1.month == d2.month && d1.year == d2.year) {  
11.         cout << "Dates are Equal!";  
12.     }  
13.     else {  
14.         cout << "Dates are not Equal!";  
15.     }  
16. }  
17.   
18. int main() {  
19.     date d1,d2;  
20.       
21.     cout << "Enter a value for day 1: ";  
22.     cin >> d1.day;  
23.       
24.     cout << "Enter a value for month 1: ";  
25.     cin >> d1.month;  
26.       
27.     cout << "Enter a value for year 1: ";  
28.     cin >> d1.year;  
29.       
30.     cout << "Enter a value for day 2: ";  
31.     cin >> d2.day;  
32.       
33.     cout << "Enter a value for month 2: ";  
34.     cin >> d2.month;  
35.       
36.     cout << "Enter a value for year 2: ";  
37.     cin >> d2.year;  
38.       
39.     compare(d1,d2);  
40. }  

BSCS-1B
PROGRAMMING FUNDAMENTAL (PF) LAB
SZABIST-ISB
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology 9

Screenshot of Output:

BSCS-1B
PROGRAMMING FUNDAMENTAL (PF) LAB
SZABIST-ISB

You might also like