Saturday, 29 August 2015
calculate grade by using pointer in classes
#include "stdafx.h"
#include<iostream>
#include<string>
#include <iomanip>
using namespace std;
class page
{
public:
int pageno;
string pagetitle;
string pagecontant;
page *pre;
};
void main()
{
page *firstpage=NULL;
int tp;
cout<<"Enter the number of pages "<<endl;
cin>>tp;
for (int i=1;i<=tp;i++)
{
page *newpage=new page();
cout<<"Enter Page number "<<endl;
cin>>newpage->pageno;
cout<<"Enter Page Title "<<endl;
cin>>newpage->pagetitle;
cout<<"Enter Page contant "<<endl;
cin>>newpage->pagecontant;
newpage->pre=firstpage;
firstpage=newpage;
}
page *temp=firstpage;
while (temp!=NULL)
{
cout<<"The page no is "<<temp->pageno<<endl;
cout<<"The page title "<<temp->pagetitle<<endl;
cout<<"The page contants is "<<temp->pagecontant<<endl;
temp=temp->pre;
}
temp=firstpage;
while (temp!=NULL)
{
cout<<"The page no is "<<temp->pageno<<endl;
cout<<"The page title "<<temp->pagetitle<<endl;
cout<<"The page contants is "<<temp->pagecontant<<endl;
temp=temp->pre;
}
while (temp->pre!=NULL)
{
temp=temp->pre;
}
delete temp->pre;
// p.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<iostream>
using namespace std;
class student
{
public:
int regno;
int marks;
char grade;
student *st;
};
void main()
{
student *hand=NULL;
int y;
cout<<"Enetr the student "<<endl;
cin>>y;
for (int i=1;i<=y;i++)
{
student *s1=new student();
cout<<"regno"<<endl;
cin>>s1->regno;
cout<<"Enter marks"<<endl;
cin>>s1->marks;
s1->st=hand;
if (s1->marks >=60)
s1->grade='A';
else
s1->grade= 'F';
hand=s1;
}
student *temp=hand;
while (temp!=NULL)
{
cout<<"Reg no is = "<<temp->regno<<endl;
cout<<"marks is = "<<temp->marks<<endl;
cout<<"The grade is "<<temp->grade<<endl;
temp=temp->st;
}
system("pause");
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment