Narue 5,707 Bad Cop Team Colleague

However, your reply is the most inefficient way of helping.

If by "inefficient" you mean that your problem is solved more slowly due to being forced to actually learn something, then I agree. But my goals are different from yours; I'm interested in the bigger picture of teaching programming while you're just interested in solving the immediate problem.

A suggested solution without an explanation or any comments isn't very useful in my case.

Unless your case is acute mental retardation, a C++ reference site and about five minutes of thought are all that's needed to understand the code without any explanation or comments. And the reference site is optional.

Narue 5,707 Bad Cop Team Colleague

I suspect that it was trying to free a pointer that doesn't exist which kind of doesn't make sense.

This is a case where I don't see an immediate problem. It would probably take some debugging, but as I cannot reproduce the error, I can't help too much. It's a shame, because I'd be interested to know exactly what's causing your error.

I know it's important to free buffers we don't need anymore from the memory but do we need to free(src)?

Unless the process lives for a long time, it's not technically necessary. On modern operating systems the memory allocated dynamically will be freed when the process terminates. However, one can't determine conclusively how library functions such as split_str() might be called, so it's an excellent idea to clean up after yourself.

You can get rid of the allocation entirely (and thus the need for free()) by assuming that s is modifiable. This puts the onus on the caller to refrain from calling split_str() with something like a string literal. The reason for that is strtok() modifies the source string, and string literals are read-only:

char **split_str(char *s, const char *delim)
{
    /*
      Error handling omitted for brevity
    */
    char **dst = malloc(sizeof *dst);
    char *tok = strtok(s, delim);
    size_t n = 0;

    while (tok != NULL) {
        dst = realloc(dst, ++n * sizeof *dst);
        dst[n - 1] = copy_str(tok);
        tok = strtok(NULL, delim);
    }

    dst[n] = NULL;

    return dst;
}
Narue 5,707 Bad Cop Team Colleague

That code still doesn't compile (which suggests that you're not showing me your actual code), and when I fix the syntax error on your fgets() call, it doesn't fault on my system.

Narue 5,707 Bad Cop Team Colleague

If someone could help me with the most efficient way, I would greatly appreciate it.

Your code is I/O bound, "efficient" shouldn't enter your vocabulary unless user testing shows perceived performance to be unacceptable. Though since you asked, I would prefer accepting a series of base/height pairs on the same line. That way you don't keep bugging the user with prompts:

string line;

if (getline(cin, line)) {
    stringstream sep(line);
    double base, height;

    while (sep >> base >> height)
        cout << "The area of the triangle is: " <<  height * base / 2 << '\n';
}
Narue 5,707 Bad Cop Team Colleague

Please post a complete main() function that exhibits the problem. The snippets you posted are clearly not the code you're trying to execute because they won't compile.

Narue 5,707 Bad Cop Team Colleague
dst = realloc(dst, ++n);

It should be this:

dst = realloc(dst, ++n * sizeof *dst);

And that, my friend, is proof that regardless of your experience or ability, stupid mistakes happen. Especially if you work with higher level language too often and then drop down to a low level language that doesn't hold your hand. ;)

Narue 5,707 Bad Cop Team Colleague

Read Me. Either cast the result of the expression, or use a larger type. Typically, there's nothing wrong with using int for all of your signed integer needs to conform to defaults, even if you don't plan to use the full 32-bit range.

Narue 5,707 Bad Cop Team Colleague

I don't know how to call a method from abstract class in protected method.

Unless the method is static you don't call it. That's the idea: abstract classes cannot be instantiated and must be inherited from to be used in any useful manner.

Narue 5,707 Bad Cop Team Colleague

Good God, can't you STFW? This question is so very common, and has been answered many times even on Daniweb.

Narue 5,707 Bad Cop Team Colleague

So it's hard to get an exact result..

Exactly. Not to mention that the most frequent cipher text letter isn't guaranteed to be an encrypted form of the most frequent alphabet letter. For example, take "thisisatest" as the plain text. Given a substitution cipher, 't' would be the most frequent letter even though 'e' is the most frequent letter in the alphabet. The general frequencies of the alphabet would only be reasonably accurate for large quantities of cipher text. Otherwise the usual frequencies are no longer statistically significant.

Frequency analysis takes at least a little bit of correctness checking by a human, otherwise you'll end up with gibberish most of the time. Alternatively you can write a fuzzy dictionary comparison and use a confidence check, but that's probably beyond your project's requirements.

How about performing multiple runs on the letters with matching frequency? Starting with the most frequent letters, you can give the user a yes/no choice on whether the result looks promising, and either continue or try again accordingly.

Narue 5,707 Bad Cop Team Colleague

Your use of strtok() is correct. The problem is your use of the uninitialized argv. You need to make sure that all destination strings have been allocated sufficient memory. Compare and contrast:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char *copy_str(const char *s)
{
    char *copy = malloc(strlen(s) + 1);
    
    if (copy != NULL)
        strcpy(copy, s);
        
    return copy;
}

char **split_str(const char *s, const char *delim)
{
    /*
        Error handling omitted for brevity
    */
    char **dst = malloc(sizeof *dst);
    char *src = copy_str(s);
    char *tok = strtok(src, delim);
    size_t n = 0;
    
    while (tok != NULL) {
        dst = realloc(dst, ++n);
        dst[n - 1] = copy_str(tok);
        tok = strtok(NULL, delim);
    }
    
    dst[n] = NULL;    
    free(src);
    
    return dst;
}

int main(void)
{
    char **s = split_str("this|is|a|test", "|");
    size_t i;
    
    for (i = 0; s[i] != NULL; i++) {
        printf("'%s'\n", s[i]);
        free(s[i]);
    }
    
    free(s);
    
    return 0;
}
Narue 5,707 Bad Cop Team Colleague

It would have been much better if you said that you're doing frequency analysis on cipher text. Then I could simply say that while frequency analysis is a good idea, your approach is too naive to produce decent results.

Can you do this analysis manually? If so, what's the process you're using? Working toward an algorithm from an already functional set of manual steps is the right approach.

Narue 5,707 Bad Cop Team Colleague

Like.. It needs to do this 26 types (to go through each number)

*sigh* I have an idea. Instead of you asking questions then invalidating the answer with new requirements, just tell us flat out everything that your program needs to do.

Narue 5,707 Bad Cop Team Colleague

That program prints 4, which is the index of 13, which is the largest number in the array. What's the problem?

Narue 5,707 Bad Cop Team Colleague

I'm working on a PDF417 recognition and decoding library for iOS.

Narue 5,707 Bad Cop Team Colleague

Heyy thanks for the reply..

It gives me 13? Which isn't the highest value

While I'm confident your code is wrong, I can't help without seeing it.

Narue 5,707 Bad Cop Team Colleague

You're overcomplicating things. Just find the index of the largest value in each array (that's two independent loops), then swap them:

int index_of_max(int a[], int size)
{
    int max = 0;

    for (int i = 1; i < size; i++) {
        if (a[i] > a[max])
            max = i;
    }

    return max;
}

...

int max1 = index_of_max(array1, size1);
int max2 = index_of_max(array2, size2);

std::swap(array1[max1], array2[max2]);
Narue 5,707 Bad Cop Team Colleague

@Narue, if that be the case, why have you decided to be a bad cop? You should be a good one.....lol:)

I figure there's enough good karma in helping people that I can afford to be an ass while doing it. ;)

Nick Evan commented: Hahaha, nice one +0
Narue 5,707 Bad Cop Team Colleague

However because I was in a good mood, I edited your post and removed your real name from it.

We're usually happy to edit out personal information, if that's the underlying reason for "please delete my thread" requests.

Narue 5,707 Bad Cop Team Colleague

But plz tell me the reason why this code is behaving unexpectedly ?

Your expectations are wrong, so the code will behave unexpectedly for you. Duh.

Narue 5,707 Bad Cop Team Colleague

So whenever a user executes the application on a system where "," is the decimal separator my result is 1.0, only on systems where "." is the decimal separator I get the correct result 1.2345.

You can change the locale temporarily. I assume your problem is that the string is always formatted using '.' as the decimal separator, so just set the locale to "C" (the default C locale) and change it back when you're done with the conversion:

#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char *copystr(const char *s)
{
    char *copy = malloc(strlen(s) + 1);
    
    if (copy != NULL)
        strcpy(copy, s);
        
    return copy;
}

double locale_atof(const char *s, const char *loc)
{
    char *p, *old_locale;
    double result;
    
    p = setlocale(LC_NUMERIC, NULL);
    
    if (p != NULL) {
        old_locale = copystr(p);
        setlocale(LC_NUMERIC, loc);
    }
        
    result = atof(s);
    
    if (p != NULL) {
        setlocale(LC_NUMERIC, old_locale);
        free(old_locale);
    }
    
    return result;
}

int main(void)
{
    double result;
    
    /* Switch to a locale with the ',' decimal character */
    setlocale(LC_NUMERIC, "German");
    printf("%s\n", localeconv()->decimal_point);
    
    /* Convert with a forced C locale */
    result = locale_atof("1.234", "C");
    
    /* Switch to the system locale for display */
    setlocale(LC_NUMERIC, "");
    printf("%f\n", result);
    
    return 0;
}
Narue 5,707 Bad Cop Team Colleague

What I came to know from google is that Bit shifting allows for compact storage of similar data as a single integral value.

It's not just shifting, and that's not the only use of the bitwise operators. Since a byte is the smallest addressable unit in C#, that's typically the smallest object one works with. But bytes are comprised of bits, and the bitwise operators allow you to work at an even smaller granularity than bytes when it makes sense to do so.

Compact storage of flags is one such use. A flag is either on or off, so there are really only two values. Rather than have an array or list of N bool objects (which still consume one byte of storage each), you can use an object with a sufficient number of bits, and then use each bit as a flag. For example with eight flags:

using System;

class Program {
    static void Main()
    {
        bool[] flagList = new bool[8] { true, false, true, true, false, true, true, false };
        byte flagByte = 0xB6;

        Console.WriteLine("flagList size: " + flagList.Length * sizeof(bool));
        Console.WriteLine("flagByte size: " + sizeof(byte));

        // List the flags in flagList
        foreach (bool flag in flagList)
            Console.Write(Convert.ToInt32(flag));

        Console.WriteLine();

        // List the flags in flagByte
        for (int bit = 7; bit >= 0; bit--)
            Console.Write((flagByte >> bit) & 0x1);

        Console.WriteLine();
    }
}

Notice how the same information was stored in 1/8th of the space using bitwise operators in the above program. This is a significant savings, …

Narue 5,707 Bad Cop Team Colleague

Here's a user control that does what you want. You can use it directly or as a template for your own ad hoc collection of controls:

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Collections.Generic;

public class SelectionList: UserControl {
    #region UI Controls
    private TableLayoutPanel tableLayoutPanelControl = new TableLayoutPanel();
    private ListBox listBoxLeft = new ListBox();
    private ListBox listBoxRight = new ListBox();
    private TableLayoutPanel tableLayoutPanelButtons = new TableLayoutPanel();
    private Button buttonAddAll = new Button();
    private Button buttonAddSelected = new Button();
    private Button buttonRemoveSelected = new Button();
    private Button buttonRemoveAll = new Button();
    #endregion

    #region UI Initialization
    private void InitializeComponent()
    {
        tableLayoutPanelControl.SuspendLayout();
        tableLayoutPanelButtons.SuspendLayout();
        SuspendLayout();

        tableLayoutPanelControl.ColumnCount = 3;
        tableLayoutPanelControl.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
        tableLayoutPanelControl.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 45F));
        tableLayoutPanelControl.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
        tableLayoutPanelControl.Controls.Add(listBoxLeft, 0, 0);
        tableLayoutPanelControl.Controls.Add(listBoxRight, 2, 0);
        tableLayoutPanelControl.Controls.Add(tableLayoutPanelButtons, 1, 0);
        tableLayoutPanelControl.Dock = DockStyle.Fill;
        tableLayoutPanelControl.Location = new Point(0, 0);
        tableLayoutPanelControl.Name = "tableLayoutPanelControl";
        tableLayoutPanelControl.RowCount = 1;
        tableLayoutPanelControl.RowStyles.Add(new RowStyle(SizeType.Percent, 100F));
        tableLayoutPanelControl.Size = new Size(178, 106);
        tableLayoutPanelControl.TabIndex = 0;
            
        listBoxLeft.Dock = DockStyle.Fill;
        listBoxLeft.FormattingEnabled = true;
        listBoxLeft.Location = new Point(3, 3);
        listBoxLeft.Name = "listBoxLeft";
        listBoxLeft.Size = new Size(60, 100);
        listBoxLeft.TabIndex = 0;
            
        listBoxRight.Dock = DockStyle.Fill;
        listBoxRight.FormattingEnabled = true;
        listBoxRight.Location = new Point(114, 3);
        listBoxRight.Name = "listBoxRight";
        listBoxRight.Size = new Size(61, 100);
        listBoxRight.TabIndex = 1;
            
        tableLayoutPanelButtons.ColumnCount = 1;
        tableLayoutPanelButtons.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F));
        tableLayoutPanelButtons.Controls.Add(this.buttonAddAll, 0, 1);
        tableLayoutPanelButtons.Controls.Add(this.buttonAddSelected, 0, 2);
        tableLayoutPanelButtons.Controls.Add(this.buttonRemoveSelected, 0, 3);
        tableLayoutPanelButtons.Controls.Add(this.buttonRemoveAll, 0, 4);
        tableLayoutPanelButtons.Dock = DockStyle.Fill;
        tableLayoutPanelButtons.Location = new Point(69, 3);
        tableLayoutPanelButtons.Name = "tableLayoutPanelButtons";
        tableLayoutPanelButtons.RowCount = 6;
        tableLayoutPanelButtons.RowStyles.Add(new RowStyle(SizeType.Percent, 50F));
        tableLayoutPanelButtons.RowStyles.Add(new RowStyle(SizeType.Absolute, 25F));
        tableLayoutPanelButtons.RowStyles.Add(new RowStyle(SizeType.Absolute, 25F));
        tableLayoutPanelButtons.RowStyles.Add(new RowStyle(SizeType.Absolute, 25F));
        tableLayoutPanelButtons.RowStyles.Add(new RowStyle(SizeType.Absolute, 25F));
        tableLayoutPanelButtons.RowStyles.Add(new RowStyle(SizeType.Percent, 50F));
        tableLayoutPanelButtons.Size = new Size(39, 100);
        tableLayoutPanelButtons.TabIndex = 2; …
Narue 5,707 Bad Cop Team Colleague

Apparently sarcasm is not as easy to detect through text as it is in person....

A cross we of the dry wit brigade must all bear.

By the way, do YOU have any information regarding PID controllers (sorry for being shameless)

Not that couldn't be gleaned from a similar Google search that I would use to fake sounding knowledgeable. ;) But for actually addressing your problem, faking it won't help.

Narue 5,707 Bad Cop Team Colleague

What exactly is it that you are thankful for? (Genuine question)

Historically, US Thanksgiving is based on various festivals from European and Native American traditions giving thanks for a good harvest. These days it's whatever is convenient in one's life, with health, wealth, and companionship being the most common thanks that are given.

As for me specifically, I'm thankful that I've had more good luck in my life than bad. ;)

Narue 5,707 Bad Cop Team Colleague

Is there any reason why the 3rd is not recommended?.. since it was the one I learned in my notes..

Global variables are difficult to work with in larger programs because they can be accessed from anywhere. Bugs where you find yourself asking "where did that variable get changed?" are greatly complicated by variables with unrestricted access.

Anyways the 'Return Method' will always work

Not always, but it should be your go to method.

Narue 5,707 Bad Cop Team Colleague

Well, seeing as no one seems to be taking my deadline as seriously as I

I would think that's obvious. Your deadline means nothing to us, and many of us are perverse enough to respond more slowly to "urgent" questions. Let's also not fail to notice that it's unreasonable to get angry that nobody in the narrow audience of VB6 PID controller writers hasn't replied after a mere two hours. :icon_rolleyes:

Narue 5,707 Bad Cop Team Colleague

How can I print it from the main? I know it sounds stupid, but I am still a beginner to the language.

There are three conventional options for accessing the calculated result in a function from the calling function:

  1. Return the result from your function:
    #include <stdio.h>
    #include <math.h>
    
    float round2int(float test)
    {
        return floor(test + 0.5);
    }
    
    int main (void)
    {
        float x;
        
        while (1) {
            printf("Enter a number (Enter zero (0) to quit program): ");
            scanf("%f", &x);
            
            if (x == 0)
                break;
                
            printf("%f\n", round2int(x));
        }
        
        return 0;
    }
  2. Pass a pointer to the destination object as an argument:
    #include <stdio.h>
    #include <math.h>
    
    void round2int(float test, float *result)
    {
        *result = floor(test + 0.5);
    }
    
    int main (void)
    {
        float x, result;
        
        while (1) {
            printf("Enter a number (Enter zero (0) to quit program): ");
            scanf("%f", &x);
            
            if (x == 0)
                break;
            
            round2int(x, &result);
            printf("%f\n", result);
        }
        
        return 0;
    }
  3. (not recommended) Use a global variable:
    #include <stdio.h>
    #include <math.h>
    
    float result;
    
    void round2int(float test)
    {
        result = floor(test + 0.5);
    }
    
    int main (void)
    {
        float x;
        
        while (1) {
            printf("Enter a number (Enter zero (0) to quit program): ");
            scanf("%f", &x);
            
            if (x == 0)
                break;
            
            round2int(x);
            printf("%f\n", result);
        }
        
        return 0;
    }
terence193 commented: Well given examples +2
Narue 5,707 Bad Cop Team Colleague

Arrays are typically viewed as so intrinsic that they're not often treated as a separate data structure. But you can certainly create an abstract data type based on at least the essential properties of the array (C++'s vector class is one such example).

Unfortunately, the question is still somewhat ambiguous. Can you give an example of an "abstract level representation" of one of the other data structures you've learned?

Narue 5,707 Bad Cop Team Colleague

My family gets together with some good ol' fashioned southern home cooking. There's nothing like binging on awesome food with good company and then not eating for the next day because you're too full. ;)

Narue 5,707 Bad Cop Team Colleague

Consider four cases given an array, a start index, and an end index:

  1. The base case where the start index passes the end index: terminate recursion.
  2. There's a vowel at the start index: recurse and increment the start index.
  3. There's not a vowel at the end index: recurse and decrement the end index.
  4. There's a vowel at the end index: swap the characters at the two indices and recurse while both incrementing the start index and decrementing the end index.
Narue 5,707 Bad Cop Team Colleague

I want to be able to display the feedback with words that are bold or different color.

Update the Font property of your rich text box.

Narue 5,707 Bad Cop Team Colleague

This is my homework :(

I guess you should have paid more attention in class then.

Narue 5,707 Bad Cop Team Colleague

It's called type punning. By casting the address of an integer into a pointer to char, you can directly access the bytes that make up the integer (note that char is synonymous with a byte).

Narue 5,707 Bad Cop Team Colleague

how can i write .

The problem you've described is adequate as either the first or second program after hello world for absolute beginners, so if you don't know where to start, I'd say start by learning a little C++.

Narue 5,707 Bad Cop Team Colleague

do you know how i can correct this?

I suspect ditching this program and starting with something smaller would be a good start, because you clearly don't have enough experience writing C++ yet. One of the most basic concepts in C++ is the distinction between a function declaration and a function definition. Without a definition (that little block of code between curly braces), you'll get undefined reference errors.

Narue 5,707 Bad Cop Team Colleague

There's nothing wrong with your code, it's the conventional recursive inorder traversal. Perhaps if you explained what you expected to happen that differs from what actually happens, someone can help you change the code to meet your needs.

Narue 5,707 Bad Cop Team Colleague

I am looking for a website that I can download Microsoft Visual c++ 6.0 or whatever it's called, the compiler.

The compiler itself is called CL.exe, but since there are so many dependent files it's best to install the IDE package.

Please give me a good up to date link that has a free full download for the compiler.

The up-to-date link is for Visual C++ 2010 Express. I'm not aware of any legal download sites for Visual C++ 6.0 (try ebay for used media). Even if there were any, I would strongly discourage use of that compiler for C++ because it's woefully inadequate. That particular version was released just before the C++ standard was finished, which means it's a bastard of the two conflicting dialects. The result is that writing C++ with Visual C++ 6.0 was an exercise in frustration.

It was a fine compiler for C though.

I can provide the header files myself

Which accomplishes nothing if you don't also have the corresponding object files. :icon_rolleyes:

Narue 5,707 Bad Cop Team Colleague

Change StrType to this:

//StrType.h
#include <fstream>
#include <iostream>
#include <cstring>

const int MAX_CHARS=100;
enum InType {ALPHA_NUM, ALPHA, NON_WHITE, NOT_NEW};

class StrType
{
public:
    void MakeEmpty();
    void GetString(bool skip, InType charsAllowed);
    void GetStringFile(bool skip, InType charsAllowed,
                       std::ifstream& inFile);
    void PrintToScreen(bool newLine);
    void PrintToFile(bool newLine, std::ofstream& outFile);
    int LenghtIs();
    void CopyString(StrType& newString);
    bool operator==(const StrType& rhs) const
    {
        return strcmp(letters, rhs.letters) == 0;
    }
    bool operator<(const StrType& rhs) const
    {
        return strcmp(letters, rhs.letters) < 0;
    }
private:
    char letters[MAX_CHARS + 1];
};

void StrType::MakeEmpty()
{
    letters[0] ='\0';
}
Narue 5,707 Bad Cop Team Colleague

No code tags, a bunch of code, and no question. Awesome. :icon_rolleyes:

Narue 5,707 Bad Cop Team Colleague

The head of the list only needs to be set if the list is presently empty. Your add_student() function always resets the head to the last node in the list during the else clause. Just cut that line out and all will be well:

if (head==NULL) {
    temp->next=head;
    head=temp;
} else {
    struct student *temp1=new struct student;
    temp1=head;
    while (temp1->next!=NULL) {
        temp1=temp1->next;
    }
    temp->next=NULL;
    temp1->next=temp;
}
Narue 5,707 Bad Cop Team Colleague

But it does not totally work yet.

Your inner loop should start at arraySize - 1 to avoid an out of bounds array access, and end at i rather than 0. Currently by going all of the way to 0, you're undoing work done previously and messing up the result.

Narue 5,707 Bad Cop Team Colleague

maybe if you could explain in pseudo what i need to do or give me an example so i can better understand what your saying

You need to write an overloaded operator==() and operator<() in your WordType class that compares the string member. Since the StrType class is also a custom class without those operations, you'll want to do the same thing there as well, where the operators perform variations of strcmp().

Narue 5,707 Bad Cop Team Colleague
#include <stdio.h>

void foo(int *p)
{
    printf("%p: %d\n", (void*)p, *p);
}

int main(void)
{
    int i = 12345;
    int *p = &i;
    
    foo(p);
    
    return 0;
}
Narue 5,707 Bad Cop Team Colleague

i m not getting what are you saying ??

Let's start over then. Your original question made no sense. Please clarify what you mean by "abstract level representation".

Narue 5,707 Bad Cop Team Colleague

i couldn't add and delete and also search...

I suspect you didn't look very hard, or looked for something complete that you could use without any thinking. But if it's the deletion for AVL trees you're having trouble finding, that's understandable. Most resources leave it as an exercise for the reader even though it's the most complex operation. :icon_rolleyes:

Fortunately for you, I scratched that particular itch with my AVL tutorial. You're welcome.

Narue 5,707 Bad Cop Team Colleague

Well, for starters you have some goofiness in your code such as using string as a variable name when it's also a type and trying to call a global function from a member function of the same name without qualification. Here's the main.cpp with those problems fixed because they're a bit more subtle:

//main.cpp
#include <fstream>
#include "StrType.h"
#include <cstddef>
#include <iostream>
#include <string>
using namespace std;

struct WordType
{
       public:
              StrType word;       
              int count;
};

struct TreeNode
{
       WordType info;
       TreeNode* left;
       TreeNode* right;
};

class ListType
{
      public:
             ListType();
             void InsertOrIncrement (StrType string);
             void Print(std::ofstream&) const;
      private:
              TreeNode* root;
};


ListType::ListType()
{
     root=NULL;
}

void Process(TreeNode*& tree, StrType s)
{
     if(tree == NULL)
     {
         tree = new TreeNode;
         tree->info.word = s;
         tree->info.count = 1;
         tree->left = NULL;
         tree->right = NULL;
     }
     else if (tree->info.word == s)
         tree->info.count++;
     else if (s < tree->info.word)
         Process(tree->left, s);
     else 
         Process(tree->right, s);
}

void ListType::InsertOrIncrement(StrType s)
{
     Process(root, s);
}

void Print (TreeNode* tree, std::ofstream& outFile)
{
     if (tree!= NULL)
     {
         Print(tree->left, outFile);
         tree->info.word.PrintToFile(true, outFile);
         outFile <<" "<< tree->info.count;
         Print(tree->right, outFile);
     }
}

void ListType::Print(std::ofstream& outFile) const
{
     ::Print(root, outFile);
}
     

int main()
{
    using namespace std;
    ListType list;
    string inFileName;
    string outFileName;
    string outputLabel;
    ifstream inFile;
    ofstream outFile;
    StrType string;
    int minimumLenght;
    
    cout<<"enter in imput file name."<<endl;
    cin>>inFileName;
    inFile.open(inFileName.c_str());
    
    cout<<"enter name of output file."<<endl;
    cin>>outFileName;
    outFile.open(outFileName.c_str());
    
    cout<<"enter name of test run."<<endl;
    cin>>outputLabel;
    outFile<< outputLabel << endl;
    
    cout<<"enter the min word size."<<endl;
    cin>>minimumLenght;
    
    string.GetStringFile(true, ALPHA_NUM, inFile);
    while(inFile)
    {
         if(string.LenghtIs() >= minimumLenght)
            list.InsertOrIncrement(string); …
Narue 5,707 Bad Cop Team Colleague

For Example, if we enter 12300 then these programs output 1 2 3 only and similarly if we enter 1000 then they only output 1.

If you have 1000 and cut off the most significant digit then that becomes 000, which is equivalent to 0. This algorithm does not work when moving from MSD to LSD for that very reason.

To fix it, you can keep an index of the digit and extract it without removing it, or simply work from LSD to MSD and reverse the digits another way (such as with recursion):

#include <iostream>

void reverse_print_digits_r(int value, int base)
{
    if (value == 0)
        return;
    
    reverse_print_digits_r(value / base, base);
    std::cout << value % base << ' ';
}

void reverse_print_digits(int value, int base)
{
    if (value == 0)
        std::cout << "0";
    else
        reverse_print_digits_r(value, base);
}

int main()
{
    int value;
    
    std::cout << "Enter a value: ";
    
    if (std::cin >> value) {
        reverse_print_digits(value, 10);
        std::cout << '\n';
    }
}
Narue 5,707 Bad Cop Team Colleague

Your algorithm is a little goofy. I think a more intuitive algorithm would match the way one might do it manually:

  1. Find the first non-vowel and mark it y, this is the end of the vowel half
  2. Find the next vowel and mark it x
  3. Swap the characters at y and x
  4. Increment y
  5. Repeat at 2 until x reaches the end of the list

This is easily translated to C++, and only requires a way to determine whether the specified character is a vowel:

void vowel_partition(char a[], int n)
{
    int x = 0;
    
    // Find the first non-vowel
    while (x < n && is_vowel(a[x]))
        ++x;
    
    // Swap in any remaining vowels
    for (int y = x; x < n; x++) {
        if (is_vowel(a[x])) {
            std::swap(a[x], a[y]);
            ++y;
        }
    }
}
Narue 5,707 Bad Cop Team Colleague
void color(int a,int b)

Two parameters.

bObj->color(10,20,30);

Three arguments.

I see what you wanted to happen, but it won't work because ducati's version of color() is an overload rather than an override. When looking at the object through a pointer to bike, you can only see the public member functions declared in bike. Since the three parameter version of color() is added in ducati, it's not visible from a pointer to bike even if that pointer points to a ducati object.

You can achieve something similar with judicious constructor parameters, virtual member functions, and polymorphism:

#include <iostream>

using namespace std;

class bike
{
public:
    bike() {
        cout << "bike()\n";
    }
    bike(int a) {
        cout << "bike(int a)\n";
    }
    virtual void color(int a, int b) {
        cout<<"Inside Bike Color"<<endl;
    }
};

class ducati : public bike
{
public:
    ducati(int a): bike(a) {
        cout << "ducati(int a)\n";
    }
    ducati(int a, int c): bike(a) {
        cout << "ducati(int a, int c)\n";
    }
    virtual void color(int a, int b) {
        cout<<"Inside Ducati Color"<<endl;
    }
};

int main()
{
    ducati monster(0, 30);
    bike *bObj = &monster;
    
    bObj->color(10, 20);
}