c++ program(classes using pointers)

i want this program using pointers

Page 1 of 1

1 Replies - 1578 Views - Last Post: 07 September 2008 - 08:40 AM Rate Topic: -----

#1 gaurav_9088  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 07-September 08

c++ program(classes using pointers)

Post icon  Posted 07 September 2008 - 05:33 AM

 #include<iostream.h>
#include<conio.h>

class student
{        int i;
char name[20];
int mark[5];
 float per;

public:

void getmark();
void show();
};
void student::getmark()
{ int i;
cout<<"enter the marks:"<<endl;
	 for(i=0;i<=4;i++)
{
   cin>>mark[i];
   per=(float)(mark[0]+mark[1]+mark[2]+mark[3]+mark[4])/5;
 }

cout<<"enter the name";
cin>>name;


}
void student::show()
{

cout<<"name="<<name<<endl;
for(i=0;i<=4;i++)
 {
   cout<<"mark="<<mark[i]<<"\n";
 }
cout<<"per="<<per<<"\n";

}

void main()

{

student s;

s.getmark();
s.show();
getch();
}
[/i]
MOD EDIT: Please :code:
Thanks, gabehabe :)

Is This A Good Question/Topic? 0
  • +

Replies To: c++ program(classes using pointers)

#2 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1138
  • View blog
  • Posts: 7,110
  • Joined: 07-September 06

Re: c++ program(classes using pointers)

Posted 07 September 2008 - 08:40 AM

Well, considering that you are using a single class this isn't overly difficult:

Change this:
void main()  
  
{  
  
student s;  
  
s.getmark();  
s.show();  
getch();  
}  


to this:
void main()  
  
{  
  
student* s = new student();  
  
s->getmark();  
s->show();  
getch();  
}  


HTH
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1