Programming
fundamental
by
Muhammad Sufyan (BS-CS)
Submitted to: RAHEEL BAIG
Subject: programming fundamental
Date: 22/03/2024
Assignment no # 5
Structure program write four property and set and display
two methods.
#include<iostr
eam> using
namespace std;
struct student
{
int
rollno;
string
name;
string
fatherName;
float marks;
};
int main()
{
student st1;
cout << " \n Student st1 "
<< endl; cout << "Enter
your Rollno:";
cin >> st1.rollno;
cout << "Roll no =" <<
st1.rollno << endl; cout <<
"Enter your Name:";
cin >> st1.name;
cout << "Name =" <<
st1.name << endl; cout <<
"Enter your fatherName:";
cin >> st1.fatherName;
cout << "FatherName =" <<
st1.fatherName << endl; cout <<
"Enter your Marks:";
cin >> st1.marks;
cout << "Marks =" << st1.marks << endl;
student st2;
cout << "\n Student st2 "
<< endl; cout << "Enter
your Rollno:";
cin >> st2.rollno;
cout << "Roll no =" <<
st2.rollno << endl; cout <<
"Enter your Name:";
cin >> st2.name;
cout << "Name =" <<
st2.name << endl; cout <<
"Enter your fatherName:";
cin >> st2.fatherName;
cout << "FatherName =" <<
st2.fatherName << endl; cout <<
"Enter your Marks:";
cin >> st2.marks;
cout << "Marks =" << st2.marks << endl;
student st3;
cout << " \n Student st3 "
<< endl; cout << "Enter
your Rollno:";
cin >> st3.rollno;
cout << "Roll no =" <<
st3.rollno << endl; cout <<
"Enter your Name:";
cin >> st3.name;
cout << "Name =" <<
st3.name << endl; cout <<
"Enter your fatherName:";
cin >> st3.fatherName;
cout << "FatherName =" <<
st3.fatherName << endl; cout <<
"Enter your Marks:";
cin >> st3.marks;
cout << "Marks =" <<
st3.marks << endl; return 0;
}
Output:
Student st1
Enter your
Rollno:1
Roll no =1
Enter your
Name:zoya
Name =zoya
Enter your
fatherName:sagheer
FatherName
=sagheer
Enter your
Marks:567
Marks =567
Student st2
Enter your
Rollno:2
Roll no =2
Enter your
Name:asma Name
=asma
Enter your
fatherName:akhtar
FatherName
=akhtar
Enter your
Marks:568
Marks =568
Student st3
Enter your
Rollno:3
Roll no =3
Enter your
Name:aleeza
Name =aleeza
Enter your
fatherName:amjad
FatherName
=amjad
Enter your
Marks:569
Marks =569
Second way too write program.
#include
<iostream>
using
namespace std;
struct student
{
int
rollno;
string
name;
string
fatherName;
float marks;
void input() {
cout << "\nEnter
Roll No: "; cin >>
rollno;
cout << "Enter
Name: "; cin >>
name;
cout << "Enter Father's
Name: "; cin >>
fatherName;
cout << "Enter
Marks: "; cin >>
marks;
}
};
int main() {
const int
numStudents = 3;
student
st[numStudents];
for (int i = 0; i < numStudents; i++) {
cout << "\nStudent " << i + 1
<< ":" << endl; st[i].input();
}
return 0
}
Output:
Student 1:
Enter Roll
No: 1 Enter
Name: zoya
Enter Father's Name:
sagheer Enter Marks:
578
Student 2:
Enter Roll
No: 2 Enter
Name: asma
Enter Father's
Name: akhtr Enter
Marks: 579
Student 3:
Enter Roll
No: 3 Enter
Name: aleeza
Enter Father's
Name: amjad Enter
Marks: 610