/* I write this pro in single linked list useing stuck how i convert it to class..



#include <cstdlib>
#include <iostream>
#include <string>
#include <sstream>


using namespace std;
struct studentinfo
{
string FName;
string LName;
int no;
int age;
struct studentinfo *next;
}
*head=NULL;


void add_studentinfo(int s);
void print_list();


int main(int argc, char *argv[])
{
int studentNo=0;
char choice;
do
{
add_studentinfo(studentNo);
cout << endl << "Do you want to add another student : (Y/N) ";
cin >> choice;
choice=toupper(choice);
studentNo++;
}
while(choice=='Y');
print_list();
system("PAUSE");
return EXIT_SUCCESS;
}
void add_studentinfo(int s)
{
struct studentinfo *temp=new struct studentinfo;
cout <<"\n Student first name: ";
cin >> temp->FName;
cout <<"Student last name: ";
cin >> temp->LName;
cout <<"Student age: ";
cin>>temp->age;
temp->no=s;


if (head==NULL)
{
temp->next=head;
head=temp;
}
else
{
struct studentinfo *temp1=new struct studentinfo;
temp1=head;
while (temp1->next!=NULL) {
temp1=temp1->next;
}



temp->next=NULL;
temp1->next=temp;
head=temp;
}
}


void print_list()
{
struct studentinfo *temp=new struct studentinfo;
temp=head;
while (temp !=NULL)
{
cout << "\n\n Student name: " << temp->FName << " " << temp->LName;
cout << "\nStudent no:   " << temp->no;
cout << "\nStudent age:  " << temp->age;
cout << endl << "--" << endl;
temp=temp->next;
}
cout << endl;
}

Edited 3 Years Ago by Nick Evan: Fixed formatting

1) Make a backup copy of your program.
2) Change the word "struct" to the word "class"
3) Attempt to compile.

Once the errors are fixed, you will understand.

This article has been dead for over six months. Start a new discussion instead.