You are on page 1of 6

PROGRAMMING FUNDAMENTALS (CSC131) Ayesha zaheer | pg#

LAB 9
TASK1:
#include<iostream>

using namespace std;

struct book_data {

int ISBN;

string book_name;

float book_pr;

};

int main() {

struct book_data book[5];

book[0].ISBN = 3456; // Add a semicolon here

book[0].book_name = "all is well";

book[0].book_pr = 1300;

for (int i = 0; i < 5; i++) {

cout << "Enter ISBN: ";

cin >> book[i].ISBN;

cout << "Enter name: ";

cin.ignore(); // Clear the newline character from the buffer

getline(cin, book[i].book_name);

cout << "Enter price: ";

cin >> book[i].book_pr;

Instructor: Mahrose Fatima Naqvi


PROGRAMMING FUNDAMENTALS (CSC131) Ayesha zaheer | pg#

return 0;

TASK 2:
#include <iostream>

#include <string>

using namespace std;

// Define a structure to represent student data

struct Student_Data {

int Roll_No;

string Name;

float Marks;

};

// Function to display student data

void displayStudentData(const Student_Data& student) {

cout << "Roll No: " << student.Roll_No << endl;

Instructor: Mahrose Fatima Naqvi


PROGRAMMING FUNDAMENTALS (CSC131) Ayesha zaheer | pg#

cout << "Name: " << student.Name << endl;

cout << "Marks: " << student.Marks << endl;

cout << endl;

int main() {

const int numStudents = 5;

Student_Data students[numStudents];

// Input data for 5 students

for (int i = 0; i < numStudents; i++) {

cout << "Enter Roll No for Student " << i + 1 << ": ";

cin >> students[i].Roll_No;

cin.ignore(); // Clear the newline character from the buffer

cout << "Enter Name for Student " << i + 1 << ": ";

getline(cin, students[i].Name);

cout << "Enter Marks for Student " << i + 1 << ": ";

cin >> students[i].Marks;

// Display the stored student data using the displayStudentData function

cout << "Student Details:" << endl;

for (int i = 0; i < numStudents; i++) {

cout << "Student " << i + 1 << ":" << endl;

displayStudentData(students[i]);

Instructor: Mahrose Fatima Naqvi


PROGRAMMING FUNDAMENTALS (CSC131) Ayesha zaheer | pg#

return 0;

Task 3:
#include <iostream>

#include <string>

using namespace std;

// Define a structure to represent employee data

struct Employee {

int ID;

string Name;

double Salary;

Instructor: Mahrose Fatima Naqvi


PROGRAMMING FUNDAMENTALS (CSC131) Ayesha zaheer | pg#

};

int main() {

// Declare an instance of the Employee structure

Employee emp;

// Input employee data

cout << "Enter Employee ID: ";

cin >> emp.ID;

cin.ignore(); // Clear the newline character from the buffer

cout << "Enter Employee Name: ";

getline(cin, emp.Name);

cout << "Enter Employee Salary: ";

cin >> emp.Salary;

// Display the stored employee data

cout << "\nEmployee Details:" << endl;

cout << "Employee ID: " << emp.ID << endl;

cout << "Employee Name: " << emp.Name << endl;

cout << "Employee Salary: " << emp.Salary << endl;

return 0;

Instructor: Mahrose Fatima Naqvi


PROGRAMMING FUNDAMENTALS (CSC131) Ayesha zaheer | pg#

Instructor: Mahrose Fatima Naqvi

You might also like