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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:37:20+00:00 2026-06-04T07:37:20+00:00

I know that if there is even no object in array there is still

  • 0

I know that if there is even no object in array there is still some address. But I want to find solution to check if there is an object under the specific index we will ask. I need to have such mechanism to adding new Points to polygon. But before that I need to know if counter of object should grow or stay in the same value if there was an object. Maybe I should try fill all array with NULL?

main.cpp

#include <iostream>
#include "punkt.h"
#include "wielokat.h"

using namespace std;

int main(int argc, char *argv[])
{
    Punkt  p1("p1", 10, 20); // 10x20
    Punkt  p2("p2", 1, 1);   //1x1

    Wielokat w1 ("square", 4);

    w1.set(p1,0);
    w1.set(p2,0);
    w1.showWielokat();


    system("PAUSE");
    return EXIT_SUCCESS;
}

Wielokat.cpp

#include "punkt.h"
#include "wielokat.h"
#include <iostream>

using namespace std;

void Wielokat::increase(int n)
{
    m_ilosc = m_ilosc + n;
    m_tab = new Punkt * [m_ilosc];  
    cout<<"Dodaj "<<m_ilosc<<endl;
}

void Wielokat::decrease(int n)
{
    m_ilosc = m_ilosc - n;
    if(m_ilosc<0){ m_ilosc=0;}
    m_tab = new Punkt * [m_ilosc]; 
    cout<<"Odejmij "<<m_ilosc<<endl;
}
void Wielokat::set(Punkt p, int pos)
{
    //How to check if there was already object ?
    m_tab[pos] = new Punkt(p);
    m_counter++;
}

void Wielokat::showWielokat()
{
    for(int i=0; i<m_counter; i++){
        m_tab[i]->show();
    }

}
void Wielokat::crash(int pos){
    //after delete all elements moved one by one to the left side
    delete m_tab[pos];
    for(int i=pos; i<m_ilosc; i++){
        m_tab[i]=m_tab[pos+1];
    }
}
double Wielokat::getParimeter(){
    //here is function whih will count circuit 
}

Wielokat.h

class Wielokat {

    public:

    Wielokat(char* nazwa, int ilosc):m_nazwa(nazwa), m_ilosc(ilosc) 
    {
        m_tab = new Punkt * [m_ilosc]; 
        m_counter = 0;
    }

    Wielokat(const Wielokat& p): m_ilosc(p.m_ilosc), m_nazwa(strdup(p.m_nazwa))
    {}

    ~Wielokat()
    {
        for(int i=0; i<m_counter; i++){
            delete m_tab[i];
        }
        delete m_tab;
    }

    //Function:
    void increase(int n);
    void decrease(int n);
    void set(Punkt p, int pos);
    void crash(int pos);  //delete
    void showWielokat();
    double getParimeter();



    private:
    Punkt **m_tab;  //our tab of elemenst
    char* m_nazwa;
    int m_ilosc;
    int m_counter;
};
  • 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-04T07:37:22+00:00Added an answer on June 4, 2026 at 7:37 am

    You are coding in C++, which means you can have an std::vector<Punkt> (or an std::vector<Punkt*>, if polymorphism were required). Don’t reinvent the wheel; use it.

    With an std::vector all of the manual allocation code is simply not required and you can check how many elements there are with vec.size().

    Update: OK, so you can’t use vector because this is homework.

    The alternative solution is to zero out the memory of your array whenever you initialize it and then check if m_tab[i] == 0 before trying to use object i. Using memset, that would look like

    // WARNING! INCOMPLETE/BUGGY CODE!
    m_tab = new Punkt* [m_ilosc];
    memset(m_tab, 0, m_ilosc * sizeof(m_tab[0]));
    

    And since you are doing this from two places in the class, you should move this logic inside a separate private method.

    Regarding the incomplete/buggy part, those two lines above have a few problems:

    1. The “old” array (if one exists) is not delete[]d; this is a memory leak.
    2. The values from the “old” array (if one exists) should be copied to the new array; the way things are now they are simply lost.

    You should fix these as the next step.

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

Sidebar

Related Questions

i know that there is some rules and standards in css handling but i
I know that there are lots of examples out there on this, but they
I know that there can be multiple values for an email, but I'm not
I know that there are many Delphi database related questions available, but I'm considering
I know that there are so many standards for writing code. And some policy
I know that there're stdout/in/err for a program and I want to redirect a
Is there an easy way to copy a nested Array so that every object
I know that there is an allocator for user applications than handles lots of
I know that there is no return type of the constructors in C++ However,
I know that there are 3 different binding contexts or load contexts: Load LoadFrom

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.