This question already has an answer here:
#include<iostream>
#include<string.h>
#include<conio.h>
#include<stdio.h>
using namespace std;
class Student{
private:
char name[20];
float marks;
float percentage;
int rollNo;
public:
void read_data(){
char *p;
cout<<"Enter Name: ";
cin>>name;
fflush(stdin);
cout<<"Enter Roll Number: ";
cin>>rollNo;
cout<<"Enter Total Marks Of 5 Subjects: ";
cin>>marks;
}
void display_data(){
cout<<"Name: "<<name<<endl;
cout<<"Roll Number: "<<rollNo<<"\n";
cout<<"Marks: "<<marks<<"\n";
cout<<"Percentage Computed: "<<percentage<<"\n\n";
}
void compute_data(){
percentage = marks/ 5;
}
};
int main(){
Student s[3];
int i=0;
for(i=0;i<=2;i++){
s[i].read_data();
s[i].compute_data();
}
for(i=0;i<=2;i++){
s[i].display_data();
}
getch();
}
how can I get the full name in the output? why 'name' variable is not storing the full name i.e "Tushar Rawat"?what are the different ways to resolve this problem in c++11?? please tell me As soon as possibleenter image description here
Aucun commentaire:
Enregistrer un commentaire