0% found this document useful (0 votes)
143 views6 pages

Fundamentals of Programming: Lab Report # 13

The document contains code for 3 programming tasks. Task 1 involves storing student data like roll number, name, age, and marks in a structure and printing it. Task 2 involves storing information of multiple students in an array of structures, and defining functions to print names of students with a given age or roll number parity. Task 3 compares two dates entered by the user which are stored in a Date structure, and prints whether they are equal or not. Each task section contains the code, inputs, and output screenshot.

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)
143 views6 pages

Fundamentals of Programming: Lab Report # 13

The document contains code for 3 programming tasks. Task 1 involves storing student data like roll number, name, age, and marks in a structure and printing it. Task 2 involves storing information of multiple students in an array of structures, and defining functions to print names of students with a given age or roll number parity. Task 3 compares two dates entered by the user which are stored in a Date structure, and prints whether they are equal or not. Each task section contains the code, inputs, and output screenshot.

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

Shaheed Zulfikar Ali Bhutto Institute of Science & Technology 8

COMPUTER SCIENCE DEPARTMENT

Fundamentals of
Programming
(LAB)
Lab Report # 13

Submitted To:

Student Name:

Reg. Number:

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

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 8

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.   
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;   

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

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++) {  
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:

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

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
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);  

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

40. }  

Screenshot of Output:

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy