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

Bca Lab Program4

The document describes a C++ program that defines a 'Student' class with two methods: 'readDetails()' for inputting student information and 'displayDetails()' for printing that information. The program prompts the user for the student's name, year of admission, marks, and address, and then displays the collected details in a formatted manner. An example output is provided, showing how the program operates with sample input.
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)
17 views2 pages

Bca Lab Program4

The document describes a C++ program that defines a 'Student' class with two methods: 'readDetails()' for inputting student information and 'displayDetails()' for printing that information. The program prompts the user for the student's name, year of admission, marks, and address, and then displays the collected details in a formatted manner. An example output is provided, showing how the program operates with sample input.
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

4. . Write a program by creating a class named 'Student' having two methods.

Perform the following:


a. First method named as 'readDetails()‟ This method should accept the following details from the
user:
 Student's name (string)
 Year of admission (string)
 Student's marks (float)
 Address (string)
b. Second method „displayDetails()‟ that would print the information (name, year of admission,
marks, address) of the students as follows:
Student Information:
Name: [Student's Name]
Year of Admission: [Year of Admission]
Marks: [Student's Marks]
Address: [Student's Address]

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

class Student {
public:
string name;
string yearOfAdmission;
float marks;
string address;

// Method to read student details


void readDetails() {
cout << "Enter Student's Name: ";
cin.ignore(); // Clear input buffer
getline(cin, name);

cout << "Enter Year of Admission: ";


getline(cin, yearOfAdmission);

cout << "Enter Student's Marks: ";


cin >> marks;
cin.ignore(); // Clear input buffer

cout << "Enter Student's Address: ";


getline(cin, address);
}

// Method to display student details


void displayDetails() {
cout << "\nStudent Information:\n";
cout << "Name: " << name << endl;
cout << "Year of Admission: " << yearOfAdmission << endl;
cout << "Marks: " << marks << endl;
cout << "Address: " << address << endl;
}
};

int main() {
Student student; // Create a Student object

student.readDetails(); // Read student details


student.displayDetails(); // Display student details

return 0;
}

OUTPUT:
Enter Student's Name: John Doe
Enter Year of Admission: 2020
Enter Student's Marks: 85.5
Enter Student's Address: 123 Main St

Student Information:
Name: John Doe
Year of Admission: 2020
Marks: 85.5
Address: 123 Main St

You might also like