0% found this document useful (0 votes)
13 views2 pages

Week 7 C++

Uploaded by

71762303063
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

Week 7 C++

Uploaded by

71762303063
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

PROGRAM :

#include <iostream>
#include <fstream>
using namespace std;
class Student {
private:
char name[10];
int age;
float height;
public:
void getdata() {
cout << "Enter name: ";
cin >> name;
cout << "Enter age: ";
cin >> age;
cout << "Enter height: ";
cin >> height;
ofstream f1;
f1.open("data.txt", ios::app);
f1 << name << " " << age << " " << height << endl;
f1.close(); }
void showdata() {
ifstream f2;
f2.open("data.txt");
while (f2 >> name >> age >> height) {
cout << "Name: " << name << ", Age: " << age << ", Height: " << height <<
endl; }
f2.close();
}};
int main() {
Student students[3];
for (int i = 0; i < 3; i++) {
cout << "Enter details for student " << i + 1 << ":" << endl;
students[i].getdata(); }
cout << "\nDisplaying student details" << endl;
students[0].showdata();
return 0;}

OUTPUT:
Enter details for student 1:
Enter name: sita
Enter age: 18
Enter height: 123.32
Enter details for student 2:
Enter name: ram
Enter age: 19
Enter height: 125.30
Enter details for student 3:
Enter name: riya
Enter age: 20
Enter height: 145.28

Displaying student details


Name: sita, Age: 18, Height: 123.32
Name: ram, Age: 19, Height: 125.3
Name: riya, Age: 20, Height: 145.28

You might also like