Destructor Little Help here
Apr 28, 2013 at 6:33am UTC
Hi programmers I'm doing dynamic memory allocation in add_ticket Method at line Number 111
what i wanna ask is where should i call destructor or should i say delete operator
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
#include <iostream>
#include <conio.h>
#include <string.h>
using namespace std;
class move_que;
void Final_Result(move_que,move_que,move_que); // None Member Funtions
class Viewer{
public :
Viewer * Get_Next(){ return Next_Node;}
void Set_Next(Viewer * next_node){Next_Node = next_node;}
char Get_Group(){return Group;}
void Set_Group(char group){Group = group;}
void Set_ticket(int tick){ticket = tick;}
int Get_Ticket(){return ticket;}
private :
Viewer * Next_Node;
int ticket;
char Group;
};
class move_que{
public :
move_que();
void add_ticket();
void total_vistors(char *);
int total_revenu(char *);
void papularity(char *);
~move_que(){}
private :
Viewer * front;
Viewer * rear;
int counter;
};
move_que::move_que()
{
counter = 0;
front = new Viewer();
rear = NULL;
}
int move_que::total_revenu(char * movi_name)
{
int temp = 0;
for (int i=0;i<counter;i++)
{
temp += 650;
}
if (strcmp(movi_name,"English Vinglish" ) == 0)
{
cout<<movi_name<<'\t' <<temp<<endl;
}
else if (strcmp(movi_name,"Tekken" ) == 0)
{
cout<<movi_name<<'\t' <<'\t' <<'\t' <<temp<<endl;
}
else if (strcmp(movi_name,"Harry Potter" ) == 0)
{
cout<<movi_name<<'\t' <<'\t' <<temp<<endl;
}
return temp;
}
void move_que::total_vistors(char * movi_name)
{
cout<<"Total Vistors For " <<movi_name<<" are " <<counter<<endl;
}
void move_que::papularity(char * movi)
{
Viewer * temp_front;
temp_front = front;
int female = 0;
int male = 0;
int kids = 0;
for (int i=0;i<counter;i++)
{
if (front->Get_Group() == 'f' || front->Get_Group() == 'F' )
{
female++;
}
else if (front->Get_Group() == 'm' || front->Get_Group() == 'M' )
{
male++;
}
else if (front->Get_Group() == 'k' || front->Get_Group() == 'K' )
{
kids++;
}
front = front->Get_Next();
}
if (female > male && female > kids)
{
cout<<movi<<" is papuler Amoung Female's" <<endl;
}
else if (male > female && male > kids)
{
cout<<movi<<" Is papuler amoung Male's" <<endl;
}
else if (kids > female && kids > male)
{
cout<<movi<<" is Papule amoung Kids" <<endl;
}
front = temp_front;
}
void move_que::add_ticket()
{
char temp_group;
Viewer * New_Node = new Viewer();
for (int i=0;;i++)
{
cout<<"Enter Your Social Group M/F/K(M for Male, F for Female, K for Kids: " ;
cin>>temp_group;
if (temp_group == 'm' || temp_group == 'M' ){break ;}
else if (temp_group == 'f' || temp_group == 'F' ){break ;}
else if (temp_group == 'k' || temp_group == 'K' ){break ;}
else {
cout<<"Please select a right social group" <<endl;
system("pause" );
continue ;
}
}
New_Node->Set_Group(temp_group);
if (rear == NULL)
{
New_Node->Set_Next(NULL);
rear = New_Node;
front = New_Node;
}
else
{
New_Node->Set_Next(NULL);
rear->Set_Next(New_Node);
rear = New_Node;
}
counter++;
}
int main()
{
int mov_choice = 0;
char choice;
bool quit = false ;
move_que Harry;
move_que english;
move_que Tekken;
do
{
while (quit == false )
{
cout<<"For Harry Potter Press ......1" <<endl;
cout<<"For English Vinglish Press ..2" <<endl;
cout<<"For Tekken Press ............3" <<endl;
cout<<"Please Enter Valid Choice (1-3) : " ;
cin>>mov_choice;
switch (mov_choice)
{
case 1:
Harry.add_ticket();
quit = true ;
break ;
case 2:
english.add_ticket();
quit = true ;
break ;
case 3:
Tekken.add_ticket();
quit = true ;
default :
cout<<"Please Select Right Choice" <<endl;
system("pause" );
system("cls" );
quit = false ;
}
}
cout<<"Would You Like to Buy another ticket y/Y(yes): " ;
cin>>choice;
if (choice == 'y' || choice == 'Y' )
{
quit = false ;
}
system("cls" );
}while (choice == 'y' || choice == 'Y' );
Final_Result(Harry,english,Tekken);
_getch();
}
void Final_Result(move_que Harry,move_que english,move_que Tekken)
{
int TOTAL_REVENU_1 = 0;
int TOTAL_REVENU_2 = 0;
int TOTAL_REVENU_3 = 0;
cout<<"******Response For Each Movi******" <<'\n' <<endl;
Harry.total_vistors("Harry Potter" );
english.total_vistors("English Vinglish" );
Tekken.total_vistors("Tekken" );
cout<<'\n' <<endl<<endl;
cout<<"******Revenu Genrated By Each Movi******" <<'\n' <<endl;
cout<<"Movi" <<'\t' <<'\t' <<'\t' <<"Revenu" <<'\n' <<endl;
TOTAL_REVENU_1 += Harry.total_revenu("Harry Potter" );
TOTAL_REVENU_2 += english.total_revenu("English Vinglish" );
TOTAL_REVENU_3 += Tekken.total_revenu("Tekken" );
cout<<'\n' <<"Total Revenu For The Cinema Is " <<TOTAL_REVENU_1+TOTAL_REVENU_2+TOTAL_REVENU_3<<endl;
if (TOTAL_REVENU_1 > TOTAL_REVENU_2 && TOTAL_REVENU_2 > TOTAL_REVENU_3)
{
cout<<"Harry Potter Is Best Seller Movi Of The Cinema" <<endl;
}
else if (TOTAL_REVENU_2 > TOTAL_REVENU_2 && TOTAL_REVENU_1 > TOTAL_REVENU_3)
{
cout<<"English Vinglish Is Best Seller Movi Of The Cinema" <<endl;
}
else if (TOTAL_REVENU_3 > TOTAL_REVENU_2 && TOTAL_REVENU_2 > TOTAL_REVENU_1)
{
cout<<"Tekken Is Best Seller Movi Of The Cinema" <<endl;
}
cout<<"******Popularity Of Each Movi amoung Social Group******" <<'\n' <<endl<<endl;
Harry.papularity("Harry Potter" );
english.papularity("English Vinglish" );
Tekken.papularity("Tekken" );
}
Apr 28, 2013 at 6:34am UTC
I'm using LInk linst
Topic archived. No new replies allowed.