Discussion:
Arrays Demo
Add Reply
Student Project
2024-08-28 01:45:55 UTC
Reply
Permalink
<*** Main Program ***>
#include "include\tools.hpp"

int main()
{
clear();

int signal_To_Ignore = -1;
int signal_to_Stop = -99;
int data[] = {1, 10, -1, 5, 6, -1, 7, -99, 8, 10};

cout << "\n\nOriginal array is: \n";
for (auto d : data)
{
cout << d << ", ";
}
cout << "\n\n\n";

cout << "After applying the two signals, the array becomes: \n";

for (auto d : data)
{
if (d == signal_to_Stop)
{
break;
}
else if (d == signal_To_Ignore)
{
continue;
}
else
{
cout << d << ", ";
}
}

cout << "\n\n";

return 0;
}
<*******************************************************>

<*** Tools.hpp ***>
#pragma once
#include <iostream>
#include <vector>

using namespace std;

void clear();

<*******************************************************>

<*** Tools.cpp ***>

#include "include/tools.hpp"

void clear() {
// CSI[2J clears screen, CSI[H moves the cursor to top-left corner
cout << "\x1B[2J\x1B[H";
}

<*******************************************************>
wij
2024-08-28 02:22:57 UTC
Reply
Permalink
Post by Student Project
<*** Main Program ***>
#include "include\tools.hpp"
int main()
{
lear();
int signal_To_Ignore = -1;
int signal_to_Stop = -99;
int data[] = {1, 10, -1, 5, 6, -1, 7, -99, 8, 10};
cout << "\n\nOriginal array is: \n";
for (auto d : data)
{
cout << d << ", ";
}
This is the basic problem of 'advanced' C++ for beginners: It hides the real thing from beginners.
(not just 'implement' detail, it is the basics of computation)
Bonita Montero
2024-08-28 09:46:36 UTC
Reply
Permalink
Better use std::array or a span in front of a C-array.
With that can have bounds-checking while debugging.

Loading...