Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7746215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:13:16+00:00 2026-06-01T10:13:16+00:00

#include<iostream.h> #include<conio.h> #include<string.h> class flight { private : int flightno; char source[30],destination[30]; protected :

  • 0
  #include<iostream.h>
  #include<conio.h>
  #include<string.h>
  class flight
  {
private :
int flightno;
char source[30],destination[30];
protected :
double fare;
public :
flight()
{
    flightno=0;
    source[0]='\0';
    destination[0]='\0';
    fare=0.0 ;
}
flight(int f,char s[],char d[],double fr)
{
    flightno=f;
    strcpy(source,s);
    strcpy(destination,d);
    fare=fr;
}
flight(flight &f)
{
    flightno=f.flightno;
    strcpy(source,f.source);
    strcpy(destination,f.destination);
    fare=f.fare;
}
virtual void accept()
{
    cout<<"\nEnter Fligt no :";
    cin>>flightno;
    cout<<"\nEnter source :";
    cin.getline(source,30);
    cout<<"\nEnter destination :";
    cin.getline(destination,30);
    cout<<"\nEnter fare :";
    cin>>fare;
}
virtual void display()
{
    cout<<"\nFlight number :"<<flightno;
    cout<<"\nsource        :"<<source;
    cout<<"\nDestination   :"<<destination;
    cout<<"\nflight fare   :"<<fare;
  }
   virtual double computefare()=0;
 };
 class domestic : public flight
 {
private :
int noc,noa;
double totalfare,discount;
public :
domestic()
{
    noc=0;
    noa=0;
    totalfare=0.0;
    discount=0.0;
}
domestic(int f,char s[],char d[],double fr,int nc,int na):flight(f,s,d,fr)
{
    noc=nc;
    noa=na;
    totalfare=0.0;
    discount=0.0;
}
domestic(domestic &d):flight(d)
{
    noc=d.noc;
    noa=d.noa;
    totalfare=d.totalfare;
    discount=d.discount;
}
void accept()
{
    flight::accept();
    cout<<"\nEnter no. of adults :";
    cin>>noa;
    cout<<"\nEnter no. of children :";
    cin>>noc;
}
void display()
{
    flight::display();
    cout<<"\n no. of adults :"<<noa;
    cout<<"\n no. of children :"<<noc;
    cout<<"\n total fare :"<<totalfare;
    cout<<"\n discount :"<<discount;
    if(discount!=0)
    cout<<"After disc: "<<(totalfare-discount);
}
double computefare()
{
    totalfare=noc*flight::fare*0.5+noa*flight::fare;
    if(totalfare>40000)
        discount=0.02*totalfare;
    return totalfare-discount;
}
 };
 class internatinal : public flight
 {
private :
int nop;
double totalfare,tax;
public :
internatinal()
{
    nop=0;
    totalfare=0.0;
    tax=0.0;
}
internatinal(int f,char s[],char d[],double fr,int np):flight(f,s,d,fr)
{
    nop=np;
    totalfare=0.0;
    tax=0.0;
}
internatinal(internatinal &i):flight(i)
{
    nop=i.nop;
    totalfare=i.totalfare;
    tax=i.tax;
}
void accept()
{
    flight::accept();
    cout<<"\nEnter no. of passenger :";
    cin>>nop;
}
void display()
{
    flight::display();
    cout<<"\n no. of passenger :"<<nop;
    cout<<"\n total fare :"<<totalfare;
    cout<<"\n tax :"<<tax;
    cout<<"After tax: "<<(totalfare+tax);
}
double computefare()
{
    totalfare=nop*flight::fare;
    tax=0.30*totalfare;
    return totalfare+tax;
}
 };
 int main()
 {
int i,n,ch;
double total=0;
cout<<"\n Enter no of transaction :" ;
cin>>n;
flight *f=new flight[n];
for(i=0;i<n;i++)
{
    cout<<"\n Enter 1 : domestic \n 2. internatinal :";
    cin>>ch;
    f[i]=ch==1?new domestic():new internatinal();
    f[i]->accept();
    total+=f[i]->computefare();
}
cout<<"\n totaL fare :"<<total;
getch();
return 0;
 }

I am using turdo C++ complier . My code is not able to compile the error lies in the main() in “flight *f=new flight[n];” line (error is :1.)Cannot create instance of abstract
class ‘flight’ in function main()
2.) Class ‘flight’ is abstract because of ‘flight::computefare() = 0’ in function main() ).
As far as i can remember we cannot create objects of an abstract class but we can create pointers of it. And here i am creating pointers only but still m getting this error.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T10:13:17+00:00Added an answer on June 1, 2026 at 10:13 am

    You’re creating a pointer-to-flight, but you’re also trying to create n flight objects: the array you’re creating is an array-of-flight, not an array-of-pointer-to-flight.

    So this cannot work.

    You could use for instance a std::vector<flight*> (possibly using a smart pointer inside the container too). (Or an array of pointer-to-flight.)

    For your assignment, don’t try and scrunch it all up in a single line, it buys you nothing. Write it more clearly and it will work:

    if (ch == 1)
        f[i] = new domestic();
    else
        f[i] = new internatinal();
    

    (The other option is to use a cast, but that will make that line even less readable.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#include<iostream.h> #include<conio.h> class String { char str[100]; public: void input() { cout<<Enter string :;
#include iostream class A { private: int a; public : A(): a(-1) {} int
#include stdio.h #include conio.h #include <iostream> using namespace std; int main (void) { char
#include <stdio.h> #include <string.h> #include <conio.h> #include <iostream> using namespace std; char a[21]; //
#include <iostream> #include <conio.h> using namespace std; class Base { int a; public: Base(const
#include<iostream> #include<conio.h> using namespace std; class A { public: int *p; A() { p
The following program is showing error: #include<conio.h> #include<iostream.h> int count = 0; class alpha
#include iostream #include vector class ABC { private: bool m_b; public: ABC() : m_b(false)
#include <iostream> using namespace std; int main() { double u = 0; double w
#include<iostream> using namespace std; class A { int a; int b; public: void eat()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.