0% found this document useful (0 votes)
100 views8 pages

Oop Lab 1

The document is a lab journal for an Object Oriented Programming lab course. It details 5 tasks completed by the student: 1) Create an employee structure and input/output employee data with and without functions. 2) Perform task 1 using a pointer structure. 3) Pass a structure by value and reference to functions. 4) Input marks for 5 students using a structure and calculate percentages. 5) Create a structure to store customer data and write functions to print customers below $200 balance and add $100 to balances over $1000.

Uploaded by

qfq
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)
100 views8 pages

Oop Lab 1

The document is a lab journal for an Object Oriented Programming lab course. It details 5 tasks completed by the student: 1) Create an employee structure and input/output employee data with and without functions. 2) Perform task 1 using a pointer structure. 3) Pass a structure by value and reference to functions. 4) Input marks for 5 students using a structure and calculate percentages. 5) Create a structure to store customer data and write functions to print customers below $200 balance and add $100 to balances over $1000.

Uploaded by

qfq
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/ 8

Bahria University, Lahore Campus

Department of Computer Science


Lab Journal 01
(Spring 2020)

Course: Object Oriented Programming - Lab Date: _19 feb 2020______


Course Code: CSL-210 Max Marks: 10
Faculty’s Name: Ms. Zupash Awais

Name: ___USAMAADNAN___ Enroll No: _____057______ Class: ____2b______

Objective(s):
Upon completion of this lab session, learners will be able to:
• Define structures
• Define & Implement an Array of Structures
• Pass Pointers to Structures
• Pass Structure to Function

Lab Tasks:

Task 1
Write a program to create structure named employee. Take information of employee from
user as input (EmpID, EmpName, EmpAge, EmpSalary) Display the output.

//with function

#include <iostream>
#include<string>
using namespace std;

struct employee
{

int EmpId,age;
string EmpName;
double salary;

void input()
{
cout << "Enter Employee id: "; cin >> EmpId;
cout << "Enter Employee Name: "; cin >> EmpName;
cout << "Enter Employee age: "; cin >> age;
cout << "Enter Employee salary: "; cin >> salary;

void output()
{
cout << "Employee id: "; cout<< EmpId <<endl;
cout << "Employee Name: "; cout << EmpName << endl;
cout << "Employee age: "; cout << age << endl;
cout << "Employee salary: "; cout << salary << endl;

};
%
Enrollment Number: ____________________________
int main()
{
employee a;
a.input();
a.output();

return 0;
}

//without function
#include <iostream>
#include<string>
using namespace std;

struct employee
{

int EmpId, age;


string EmpName;
double salary;

};

int main()
{
employee a;

cout << "Enter Employee id: "; cin >> a.EmpId;


cout << "Enter Employee Name: "; cin >> a.EmpName;
cout << "Enter Employee age: "; cin >> a.age;
cout << "Enter Employee salary: "; cin >> a.salary;

cout << "Employee id: "; cout << a.EmpId << endl;
cout << "Employee Name: "; cout << a.EmpName << endl;
cout << "Employee age: "; cout << a.age << endl;
cout << "Employee salary: "; cout << a.salary << endl;

return 0;
}

Employee with array


#include <iostream>
#include<string>
using namespace std;

struct employee
{

int EmpId, age;


string EmpName;
double salary;

};

int main()
{
employee a[5];

Page 2 of 8
%
Enrollment Number: ____________________________

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


{

cout << endl;


cout << "Enter Employee id: "; cin >> a[i].EmpId;
cout << "Enter Employee Name: "; cin >> a[i].EmpName;
cout << "Enter Employee age: "; cin >> a[i].age;
cout << "Enter Employee salary: "; cin >> a[i].salary;

cout << endl;


}

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


{
cout << endl;

cout << "Enter Employee id: "; cout << a[i].EmpId <<endl;
cout << "Enter Employee Name: "; cout << a[i].EmpName << endl;
cout << "Enter Employee age: "; cout << a[i].age << endl;
cout << "Enter Employee salary: "; cout << a[i].salary << endl;

cout << endl;


}

return 0;
}

Task 2
Perform Task 1 using pointer structure.

#include <iostream>
#include<string>
using namespace std;

struct employee
{

int EmpId, age;


string EmpName;
double salary;

};

int main()
{
employee *a,p;
a = &p;

cout << "Enter Employee id: "; cin >> (*a).EmpId;


cout << "Enter Employee Name: "; cin >> (*a).EmpName;
cout << "Enter Employee age: "; cin >> (*a).age;
cout << "Enter Employee salary: "; cin >> (*a).salary;

Page 3 of 8
%
Enrollment Number: ____________________________

cout << "Employee id: "; cout << (*a).EmpId << endl;
cout << "Employee Name: "; cout << (*a).EmpName << endl;
cout << "Employee age: "; cout << (*a).age << endl;
cout << "Employee salary: "; cout << (*a).salary << endl;

return 0;
}

Task 3
Perform Task 1 and display the output using function. Pass the structure object in function
first by value and then by reference.

#include <iostream>
#include<string>
using namespace std;

struct employee
{

int EmpId, age;


string EmpName;
double salary;

void input()
{
cout << "Enter Employee id: "; cin >> EmpId;
cout << "Enter Employee Name: "; cin >> EmpName;
cout << "Enter Employee age: "; cin >> age;
cout << "Enter Employee salary: "; cin >> salary;

};

void output(employee a)
{
cout << "Employee id: "; cout << a.EmpId << endl;
cout << "Employee Name: "; cout << a.EmpName << endl;
cout << "Employee age: "; cout << a.age << endl;
cout << "Employee salary: "; cout << a.salary << endl;

int main()
{
employee a;
a.input();
output(a);

return 0;
}

Page 4 of 8
%
Enrollment Number: ____________________________

Task 4
Enter the marks of 5 students in Computer Programming, ICT and Object-Oriented
Programming (each out of 100) using a structure named Marks having elements roll no.,
name, cp_marks, ict_marks and oop_marks and then display the percentage of each student.

#include <iostream>
#include<string>
#include<conio.h>
using namespace std;

struct Marks
{
int rollno;
double cpmarks,ictmarks,oppmarks;
string name;

};

int main()
{
Marks student[5];

cout << "this program is for only five students" <<endl <<endl;

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


{

cout << endl;


cout << "Enter Student roll number: "; cin >> student[i].rollno;
cin.ignore();
cout << "Enter " << student[i].rollno << " Student name : ";
getline( cin,student[i].name);
cout << "Enter " << student[i].name << " cp marks: "; cin >>
student[i].cpmarks;
cout << "Enter " << student[i].name << " ict marks : "; cin >>
student[i].ictmarks;
cout << "Enter " << student[i].name << " oop marks : "; cin >>
student[i].oppmarks;
cout << endl;

cout << "press any key to continue";


_getch();

system("cls");
}

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


{
cout << endl;
cout << "Student roll number: "; cout<< student[i].rollno <<endl;
cout << "Student" << student[i].rollno <<"name: "; cout <<
student[i].name << endl;
cout << "Student" << student[i].name << "cp marks : "; cout <<
student[i].cpmarks << endl;
cout << "Student" << student[i].name <<" ict marks : "; cout <<
student[i].ictmarks << endl;
Page 5 of 8
%
Enrollment Number: ____________________________
cout << "Student" << student[i].name <<" oop marks : "; cout <<
student[i].oppmarks << endl;
cout << endl;

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


{
double obtain[5],per[5];
obtain[i] = student[i].cpmarks + student[i].ictmarks +
student[i].oppmarks;
per[i] = (obtain[i] * 100) / 300;

cout << "percentage of " << student[i].name <<": "<< per[i] <<endl;

return 0;
}

Task 5
Write a structure to store the name, account number and balance of 50 customers and store
their information.
1 - Write a function to print the names of all the customers having balance less than $200.
2 - Write a function to add $100 in the balance of all the customers having more than $1000
in their balance and then print the incremented value of their balance.

#include <iostream>
#include<string>
#include<conio.h>
using namespace std;

struct customers
{

double balance;
string name,accno;

};

int input(customers a[], const int size)


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

cout << endl;

cout << "Enter Customer Account number : "; cin >> a[i].accno;
cin.ignore();
cout << "Enter " << a[i].accno << " Name: "; getline(cin, a[i].name);
cout << "Enter " << a[i].name << " Balance in $: "; cin >> a[i].balance;
cout << endl;

cout << "press any key to continue";


_getch();

Page 6 of 8
%
Enrollment Number: ____________________________

system("cls");
}
return 0;
}

int showname(customers a[], const int size)


{
for (int i = 0; i < size; i++)
{
if (a[i].balance < 200)
cout << a[i].name;

cout << endl;


}
return 0;
}

int increment(customers a[], const int size)


{
for (int i = 0; i < size; i++)
{
if (a[i].balance>1000)
{

a[i].balance = a[i].balance + 100;

}
return 0;

int showdetails(customers a[], const int size)


{

for (int i = 0; i < size; i++)


{

cout << endl;

cout << "Enter Customer name : "; cout << a[i].name; cout << endl;
cout << "Enter " << a[i].name << " Account Number: "; cout <<
a[i].accno; cout << endl;
cout << "Enter " << a[i].name << " Balance : "; cout << a[i].balance;
cout << endl;

return 0;
}

int main()
{
const int size = 50;
customers a[size];

cout << "this program is for only fifty customers" << endl;

input(a,size);
showname(a, size);
increment(a, size);

Page 7 of 8
%
Enrollment Number: ____________________________
showdetails(a, size);

return 0;
}

Lab Grading Sheet :


Max
Obtained
Task Mark Comments(if any)
Marks
s
1. 02
2. 02
3. 02
4. 02
5. 02
Total 10 Signature

Note : Attempt all tasks and get them checked by your Lab Instructor.

Page 8 of 8

You might also like