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 8931307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:05:10+00:00 2026-06-15T09:05:10+00:00

I am here including a simple program that written in C++ where I am

  • 0

I am here including a simple program that written in C++ where I am trying to use a parametrized constructor. My idea is to instantiate the class dynamically and capture the required task.
But whenever I run the program and enter the task 1 it simply prints the two lines (i.e. Enter Name.Enter Tel.No.). It is actually supposed to print “Enter Name.” then input the name, And then again print “Enter Tel.No.”.
How can I fix the issue? I have to use parametrized constructor dynamically while creating an object.

    #include <iostream>
    #include <conio.h>
    #include <fstream>
    #include <string>

using namespace std;

class myClass
{
     string  fullname,telephone;

public:
       myClass(int taskType = 2)
       {
          if(taskType==1)
          {
              add_record();                  
          }
          else if(taskType==2)
          {
              //view_records();
          }
          else if(taskType==3)
          {
              //delete_record();
          }else{
             // custom_error();
          }        
       }  
void add_record()
{
cout << "Enter Name.\n";
getline(cin, fullname);
cout << "Enter Tel. No.\n";
getline(cin, telephone);
}
   };

    main (){
          int myTask;
      cout << "Enter a Task-Type. \n"
           << "1 = Add Record,"
           << "2 = View Records,"
           << "3 = Delete a Record\n\n";
      cin >> myTask;
      myClass myObject(myTask);
           getch();
     }
  • 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-15T09:05:11+00:00Added an answer on June 15, 2026 at 9:05 am

    This probably has nothing to do with your constructor, but rather with the mixing of cin >> and getline. Add a getline to a garbage variable after cin >> myTask and it should work.

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

Sidebar

Related Questions

Consider the following, simple class constructor. (note that I am obviously not including all
I'm an amateur programmer. I am trying to write a simple program that will
I've read a lot, including here on SO that suggests this is a very
Ok, so I have a simple c++ program that's supposed to run a couple
I have a problem with including classes. Here's a simple example to explain the
I am trying to create a simple bar graph including two bars showing the
I am working on a simple FOSS VB.net program that operates mostly in one
I am to program a simple shell in linux that can implement various stuffs
I am making a simple program that creates game cards for a game I
Here is a simple project based on a Poco class named Task : class

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.