How to add, remove and show element in table with indicators with C++
up vote
0
down vote
favorite
I'm new with C++ and have problem with indicators
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
int * createTab(int size)
{
int * wskTab;
wskTab = new int [size];
return wskTab;
}
void fill(int * mytab, int size)
{
for(int i=0;i<size;i++) {
mytab[i]= rand()%(38-16)+16;
}
}
void show(int * mytab, int size)
{
for(int i=0;i<size;i++) {
coud<<mytab[i]<<"";
}
cout<<endl;
}
int * addElem(int size, int * mytab, int val)
{
int * nwsk = new int [size+1);
for (int i = 0; i<size ;i++) {
nwski[i] = mytab[i];
}
delete mytab;}
nwsk[size] = val;
return nwsk;
}
int * removeElem (int size, int * mytab, int id)
{
int * nwsk = new int [size -1];
for(int i = ; i < id; i++) {
nwski[i] = mytab[i];
}
for (int i = id+1; i < size; i++) {
nwski[i-1] = mytab[i];
}
delete mytab;
return nwsk;
}
And now, how to:
- Add element inside
- Remove first and last element of table
- Show piece of table
- Upgrade piece of table
c++ tabular
|
show 2 more comments
up vote
0
down vote
favorite
I'm new with C++ and have problem with indicators
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
int * createTab(int size)
{
int * wskTab;
wskTab = new int [size];
return wskTab;
}
void fill(int * mytab, int size)
{
for(int i=0;i<size;i++) {
mytab[i]= rand()%(38-16)+16;
}
}
void show(int * mytab, int size)
{
for(int i=0;i<size;i++) {
coud<<mytab[i]<<"";
}
cout<<endl;
}
int * addElem(int size, int * mytab, int val)
{
int * nwsk = new int [size+1);
for (int i = 0; i<size ;i++) {
nwski[i] = mytab[i];
}
delete mytab;}
nwsk[size] = val;
return nwsk;
}
int * removeElem (int size, int * mytab, int id)
{
int * nwsk = new int [size -1];
for(int i = ; i < id; i++) {
nwski[i] = mytab[i];
}
for (int i = id+1; i < size; i++) {
nwski[i-1] = mytab[i];
}
delete mytab;
return nwsk;
}
And now, how to:
- Add element inside
- Remove first and last element of table
- Show piece of table
- Upgrade piece of table
c++ tabular
Why are you not usingstd::vector<int>
instead ofnew
anddelete
? Looking at your code, you're trying to accomplish the same thing as 3 or 4 lines of C++ usingstd::vector
would accomplish.
– PaulMcKenzie
8 hours ago
Also, your formatting makes the code very hard to read. You should properly indent your code, instead of having all the statements start flush on the left margin.
– PaulMcKenzie
8 hours ago
PaulMcKenzie i need to do this for school. I don't know how to use command vector.
– Maciek Łuczyński
8 hours ago
vector
is not a command. It is what is used in C++ as a dynamic array. Thus your entirecreateTab
function isstd::vector<int> workTab(size);
– PaulMcKenzie
7 hours ago
1
You're new to C++, but you're being asked to code this way? Get another teacher. Removing, adding elements is 1 line of code for each, without bugs, mistakes, memory leaks, etc. What you're being taught isC
with some C++ syntax thrown in.
– PaulMcKenzie
7 hours ago
|
show 2 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm new with C++ and have problem with indicators
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
int * createTab(int size)
{
int * wskTab;
wskTab = new int [size];
return wskTab;
}
void fill(int * mytab, int size)
{
for(int i=0;i<size;i++) {
mytab[i]= rand()%(38-16)+16;
}
}
void show(int * mytab, int size)
{
for(int i=0;i<size;i++) {
coud<<mytab[i]<<"";
}
cout<<endl;
}
int * addElem(int size, int * mytab, int val)
{
int * nwsk = new int [size+1);
for (int i = 0; i<size ;i++) {
nwski[i] = mytab[i];
}
delete mytab;}
nwsk[size] = val;
return nwsk;
}
int * removeElem (int size, int * mytab, int id)
{
int * nwsk = new int [size -1];
for(int i = ; i < id; i++) {
nwski[i] = mytab[i];
}
for (int i = id+1; i < size; i++) {
nwski[i-1] = mytab[i];
}
delete mytab;
return nwsk;
}
And now, how to:
- Add element inside
- Remove first and last element of table
- Show piece of table
- Upgrade piece of table
c++ tabular
I'm new with C++ and have problem with indicators
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
int * createTab(int size)
{
int * wskTab;
wskTab = new int [size];
return wskTab;
}
void fill(int * mytab, int size)
{
for(int i=0;i<size;i++) {
mytab[i]= rand()%(38-16)+16;
}
}
void show(int * mytab, int size)
{
for(int i=0;i<size;i++) {
coud<<mytab[i]<<"";
}
cout<<endl;
}
int * addElem(int size, int * mytab, int val)
{
int * nwsk = new int [size+1);
for (int i = 0; i<size ;i++) {
nwski[i] = mytab[i];
}
delete mytab;}
nwsk[size] = val;
return nwsk;
}
int * removeElem (int size, int * mytab, int id)
{
int * nwsk = new int [size -1];
for(int i = ; i < id; i++) {
nwski[i] = mytab[i];
}
for (int i = id+1; i < size; i++) {
nwski[i-1] = mytab[i];
}
delete mytab;
return nwsk;
}
And now, how to:
- Add element inside
- Remove first and last element of table
- Show piece of table
- Upgrade piece of table
c++ tabular
c++ tabular
edited 4 hours ago
Brian Tompsett - 汤莱恩
4,153133699
4,153133699
asked 8 hours ago
Maciek Łuczyński
132
132
Why are you not usingstd::vector<int>
instead ofnew
anddelete
? Looking at your code, you're trying to accomplish the same thing as 3 or 4 lines of C++ usingstd::vector
would accomplish.
– PaulMcKenzie
8 hours ago
Also, your formatting makes the code very hard to read. You should properly indent your code, instead of having all the statements start flush on the left margin.
– PaulMcKenzie
8 hours ago
PaulMcKenzie i need to do this for school. I don't know how to use command vector.
– Maciek Łuczyński
8 hours ago
vector
is not a command. It is what is used in C++ as a dynamic array. Thus your entirecreateTab
function isstd::vector<int> workTab(size);
– PaulMcKenzie
7 hours ago
1
You're new to C++, but you're being asked to code this way? Get another teacher. Removing, adding elements is 1 line of code for each, without bugs, mistakes, memory leaks, etc. What you're being taught isC
with some C++ syntax thrown in.
– PaulMcKenzie
7 hours ago
|
show 2 more comments
Why are you not usingstd::vector<int>
instead ofnew
anddelete
? Looking at your code, you're trying to accomplish the same thing as 3 or 4 lines of C++ usingstd::vector
would accomplish.
– PaulMcKenzie
8 hours ago
Also, your formatting makes the code very hard to read. You should properly indent your code, instead of having all the statements start flush on the left margin.
– PaulMcKenzie
8 hours ago
PaulMcKenzie i need to do this for school. I don't know how to use command vector.
– Maciek Łuczyński
8 hours ago
vector
is not a command. It is what is used in C++ as a dynamic array. Thus your entirecreateTab
function isstd::vector<int> workTab(size);
– PaulMcKenzie
7 hours ago
1
You're new to C++, but you're being asked to code this way? Get another teacher. Removing, adding elements is 1 line of code for each, without bugs, mistakes, memory leaks, etc. What you're being taught isC
with some C++ syntax thrown in.
– PaulMcKenzie
7 hours ago
Why are you not using
std::vector<int>
instead of new
and delete
? Looking at your code, you're trying to accomplish the same thing as 3 or 4 lines of C++ using std::vector
would accomplish.– PaulMcKenzie
8 hours ago
Why are you not using
std::vector<int>
instead of new
and delete
? Looking at your code, you're trying to accomplish the same thing as 3 or 4 lines of C++ using std::vector
would accomplish.– PaulMcKenzie
8 hours ago
Also, your formatting makes the code very hard to read. You should properly indent your code, instead of having all the statements start flush on the left margin.
– PaulMcKenzie
8 hours ago
Also, your formatting makes the code very hard to read. You should properly indent your code, instead of having all the statements start flush on the left margin.
– PaulMcKenzie
8 hours ago
PaulMcKenzie i need to do this for school. I don't know how to use command vector.
– Maciek Łuczyński
8 hours ago
PaulMcKenzie i need to do this for school. I don't know how to use command vector.
– Maciek Łuczyński
8 hours ago
vector
is not a command. It is what is used in C++ as a dynamic array. Thus your entire createTab
function is std::vector<int> workTab(size);
– PaulMcKenzie
7 hours ago
vector
is not a command. It is what is used in C++ as a dynamic array. Thus your entire createTab
function is std::vector<int> workTab(size);
– PaulMcKenzie
7 hours ago
1
1
You're new to C++, but you're being asked to code this way? Get another teacher. Removing, adding elements is 1 line of code for each, without bugs, mistakes, memory leaks, etc. What you're being taught is
C
with some C++ syntax thrown in.– PaulMcKenzie
7 hours ago
You're new to C++, but you're being asked to code this way? Get another teacher. Removing, adding elements is 1 line of code for each, without bugs, mistakes, memory leaks, etc. What you're being taught is
C
with some C++ syntax thrown in.– PaulMcKenzie
7 hours ago
|
show 2 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
draft saved
draft discarded
draft saved
draft discarded
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53343748%2fhow-to-add-remove-and-show-element-in-table-with-indicators-with-c%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Why are you not using
std::vector<int>
instead ofnew
anddelete
? Looking at your code, you're trying to accomplish the same thing as 3 or 4 lines of C++ usingstd::vector
would accomplish.– PaulMcKenzie
8 hours ago
Also, your formatting makes the code very hard to read. You should properly indent your code, instead of having all the statements start flush on the left margin.
– PaulMcKenzie
8 hours ago
PaulMcKenzie i need to do this for school. I don't know how to use command vector.
– Maciek Łuczyński
8 hours ago
vector
is not a command. It is what is used in C++ as a dynamic array. Thus your entirecreateTab
function isstd::vector<int> workTab(size);
– PaulMcKenzie
7 hours ago
1
You're new to C++, but you're being asked to code this way? Get another teacher. Removing, adding elements is 1 line of code for each, without bugs, mistakes, memory leaks, etc. What you're being taught is
C
with some C++ syntax thrown in.– PaulMcKenzie
7 hours ago