i'm a beginner in C++
i decided to learn the Scary C++ Programing Language
i am a slow learner and after 2 Months learning C++ i saw the need to have a Nice and Tidy progress bar for my programs.
Here what i wrote:
#include <iostream>
#include <string>
#include <iomanip>
#include <unistd.h>
// That function controls the inner Bar
void printProgressBar(char fill = '.',
char highlight = '*',
int barSize = 10,
float startingProgress = 0.0f
)
{
for (int pos = 0; pos < (barSize-(startingProgress*10)); ++pos)
{
std::cout << "\r[" << std::string(pos, fill) << highlight << std::flush;
usleep(50000);
}
}
// That function controls the outer Bar
void progressBarBox(char highlight = '*', float endPoint = 1.0f){
std::cout << std::string(endPoint*10, highlight);
std::cout << ']' << std::flush;
}
int main(int argc, char* argv[]) {
const int barSize{3};
const char barFill{'.'};
const char barHighlight{'*'};
progressBarBox(barFill, barSize+0.1f);
float progress {0.0f};
while (progress < barSize)
{
printProgressBar(barFill, barHighlight, barSize*10, progress);
progressBarBox(barHighlight, progress);
progress += 0.1;
}
std::cout << "\nDone" << std::endl;
return 0;
}
The problem is: with python i never cared about best practices, clean of code or code readbility
I Have many questions about my solution
My Questions:
- How would you rate my code, what to improve ?
- how to improve his readbility?
- this code would be fine to work with or a headache to mantain, how to improve?
- is there Better ways ( that are not so complex too ) to achieve the same ? with the star moving and everything.
- Is there a best practice i'm not following or missing ?
- i hardcoded some values is that bad ?
- a friend of mine said that this code will have a bad performance because of my use of string, is that true ?
I know thats a lot of questions and i am grateful for any contribution or help.