+ 3
Write a program to accept the student detail such as name and 3 different marks by get_data() method and display the name?hlp
#include <iostream> using namespace std; class student { private : char name ; int Eng,Urdu,Maths; public : void getdata() { cout<<"\nEnter name "; cin>>name ; cout<<"\nEnter eng marks"; cin>>Eng; cout <<"\nEnter urdu marks"; cin>>Urdu; cout <<"\nEnter maths marks"; cin>>Maths; } void display() { cout <<"\nName:"<<name; cout <<"\nEng marks:"<<Eng; cout <<"\nUrdu marks:"<<Urdu; cout <<"\nMaths marks"<<Maths; } }; void main() { student obj; obj.getdata(); obj.display( ); return 0; };
10 ответов
+ 4
you did little mistakes first thing you have not mentioned char size in name Second thing in main function after last curly bracket you put semicolon . your main function is void type but u used return statement. now its working fine.
#include <iostream>
using namespace std;
class student
{ private :
char name[20] ;
int Eng,Urdu,Maths;
public :
void getdata()
{
cout<<"\nEnter name ";
cin>>name ;
cout<<"\nEnter eng marks";
cin>>Eng;
cout <<"\nEnter urdu marks";
cin>>Urdu;
cout <<"\nEnter maths marks";
cin>>Maths;
}
void display()
{
cout <<"\nName:"<<name;
cout <<"\nEng marks:"<<Eng;
cout <<"\nUrdu marks:"<<Urdu;
cout <<"\nMaths marks"<<Maths;
}
};
int main()
{
student obj;
obj.getdata();
obj.display( );
return 0;
}
........ Thankyou........
+ 4
Coz char name can store a single character only and char name[20] is an array of characters and each character will be stored in a continuous manner. For example , taking a word "world". w will be stored at name[0], o at name[1] and so on...
+ 3
Use `string` as type for the <name> field instead of `char`. And set main function return value to `int` because you return something there.
+ 3
Kindly encorrect the mistake in this code by mention the line
+ 3
Problem resolve by Ada Lovelace...... but I want to know .... how is it resolved what is the logic of ..... char name [20] ?
+ 2
C++ code help? Any one ?
+ 2
Kindly guide me ..... I can't understand my this mistake ....
+ 2
But why integer value could not be placed ?
+ 2
Could you explain your question(integer value)?
+ 1
Kaamila Salahuddin
In the class definition, inside private: section;
Change this line 👇
char name; -> string name;
And in the main function declaration;
Change this line 👇
void main() -> int main()
That's it I guess ...