Oop Lab #02
Oop Lab #02
01-133192-014
OOP LAB # 02
BEE-3A
Q No.1(a):-
Write a program in which a ‘Student’ entity is map having the following attributes:
Name
EnrollmentNumber
CGPA
DegreeProgram
In main, declare one student entity. Take the values of its members from
user and also print them.
Program:-
#include<iostream>
using namespace std;
struct student_data
{
char Name[10];
int Enrollment_Number;
float CGPA;
char Degree_Program;
};
int main()
{
student_data student1;
cout << "Enter Name of student" << endl;
cin >> student1.Name;
cout << "Enter Enrollment Number" << endl;
cin >> student1.Enrollment_Number;
cout << "Enter CGPA" << endl;
cin >> student1.CGPA;
cout << "Enter Degree Program " << endl;
cin >> student1.Degree_Program;
cout << "Enter Name of student" <<student1.Name<< endl;
cout << "Enter Enrollment Number" << student1.Enrollment_Number << endl;
cout << "Enter CGPA" << student1.CGPA << endl;
cout << "Enter Degree Program" << student1.Degree_Program << endl;
system("pause");
return 0;
Q No.1(b):-
Define a structure ‘StudentDetails’ having following attributes
Name
EnrollmentNumber
Define another structure ‘StudentResult’ having following attributes
StudentDetails
SubjectName
Marks
In main, declare an object of ‘StudentResult’. Initialize all of its members by
taking input from user. Also, print the entered values as well on console.
Program:-
#include<iostream>;
using namespace std;
struct studentdetail
{
char name[15];
char enroll[10];
};
struct studentresult
{
studentdetail d;
char subj [15];
float marks;
}r;
int main()
{
cout << " Enter your Name\n";
cin >> r.d.name;
cout << " " << r.d.name << "enter Enrollment no\n";
cin >> r.d.enroll;
cout << " " <<r.d.name <<"enter subject name\n";
cin >> r.subj;
cout << " " << r.d.name << "enter marks\n";
cin >> r.marks;
cout << endl << "Student Name is" << r.d.name << endl;
cout << endl << "Student Enrollment No.is" << r.d.enroll
<< endl;
cout << endl << "Student Subject is" << r.subj << endl;
cout << endl << "" << r.subj << "Mark is" << r.marks;
cout << endl;
system("pause");
return 0;
}
Q no. 2(a):-
Make a structure ‘Shape’ that should have following functions:
float area(float radius);llll
float area(float height, float width);
Make an instance of the structure in main and use both functions to compute the
area of circle, rectangle and square respectively. Take the required parameters from
user or you can also randomly assign them.
Program:-
#include<iostream>
using namespace std;
struct shape
{
float area(float radius)
{
float e; e = 3.14 * radius * radius; return e;
}
float area(float height, float width)
{
float a; a = height * width; return a;
}
};
void main()
{
float h, w, r, wi, hi;
shape s;
char c;
up:
cout << "enter s for square and rectangle,c for circle \n";
cin >> c;
switch (c)
{
case 's':
char w;
cout << "enter s for square or r for rectangle\n";
cin >> w;
if (w == 'r')
{
cout << "enter height of rectangle\n";
cin >> h;
cout << "enter width of rectangle\n";
cin >> w;
cout << "The area of rectangle is :-" << s.area(h, w);
}
else if (w == 's')
{
cout << "enter height and width of square \n";
cin >> hi >> wi;
cout << "The area of square is :- " << s.area(hi, wi);
}
break;
case 'c':
cout << "enter circle radius\n";
cin >> r;
cout << "The area of Circle is :-" << s.area(r);
break;
default:
cout << "enter correct character\n";
goto up;
}
cout << endl;
}
Q no.2(b):-
Write a program in which a ‘Student’ entity is map having the following attributes:
Name
EnrollmentNumber
CGPA
DegreeProgram
Reserve the memory for 2 students at compile time and make a menu which
should allow user to add the student data one by one.
Program:-
#include<iostream>
using namespace std;
struct student
{
char name[10];
char enroll[20];
float cgpa;
char degree[20];
}s[2];
int main()
{
int a;
cout << "Enter Student Numbers\n";
cin >> a;
for (int i = 0; i < a; i++)
{
cout << "Enter Your name\n";
cin >> s[i].name;
cout << " " << s[i].name << "enter Enrollment
no\n";
cin >> s[i].enroll;
cout << " " << s[i].enroll << "enter cgpa\n";
cin >> s[i].cgpa;
cout << " " << s[i].name << "enter your program\n";
cin >> s[i].degree;
}
cout << "Student Data is";
for(int i=0;i<a;i++)
{
cout << endl << "Student Name" << i+1 <<
"IS"<<s[i].name << endl;
cout << endl << "Student Enrollment No.is" <<
s[i].enroll << endl;
cout << endl << "Student CGPA is" << s[i].cgpa << endl;
cout << endl << "student Program is" << s[i].degree
<< endl;
}