Please correct my code, and teach me where is my wrong. Show full code in reply
ID: 3539279 • Letter: P
Question
Please correct my code, and teach me where is my wrong.
Show full code in reply me answer.
My code:
#include <iostream>
using namespace std;
class Ticket
{
private:
int no;
float price;
public:
Ticket()
{
price=10.00;
}
void setTicket()
{
cout<<"Please enter number of ticket to purchase: ";
cin>>no;
}
friend class Student;
}
class Student
{
private:
string name, id;
string purchase;
public:
void setStudent()
{
cout<<"Enter ID:";
cin>>id;
cout<<"Enter name";
cin>>name;
}
void ticket_entry()
{
cout<<"Do you want to purchase charity tickets? [Enter Y or N]:";
cin>>purchase;
while(purchase=='N')
{
cout<<"-------No tickets purchase-------";
}
class Ticket::setTicket();
}
void display()
{
cout<<"-------------------------------------------"<<endl;
cout<<" STUDENT DETAILS "<<endl;
cout<<"-------------------------------------------"<<endl;
cout<<"ID :"<<id<<endl;
cout<<"Name :"<<name<<endl;
}
}
int main()
{
int i;
Student S[3];
for(i=0; i<3; i++)
{
setStudent();
ticket_entry();
display();
}
return 0;
}
Explanation / Answer
in your main function you have to call the functions using the class objects.
also include string header file
i.e
int main()
{
int i;
Student S[3]; // class object
for(i=0; i<3; i++)
{
S[i].setStudent(); // use this instead of setStudent();
S[i].ticket_entry();
S[i].display();
}
system("pause");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.