Hej...
Jeg vil bare gerne have evalueret min kode..
Jeg er lige gået i gang med at programmerer C++ og er lidt i vildrede da eg godt kunne tænke mig at vide om der evt. skulle være nogle fundamentale problemer taget i betragtning af hvordan min videre udvikling af kode skal være.... jeg håbe der er en haj der lige gider tage sig tid til at kigge det igennem...
DEt er meget simpelt så det burde ikke vare lang tid for at lige kigge på
/*
The Black Box a1.1
Source by: Kent Olsen
*/
#include <iostream> // Includes
#include <string>
#include <sstream>
#define dbl_upper_left_corner char(0xc9) // Defines
#define dbl_upper_right_corner char(0xbb)
#define dbl_lower_left_corner char(0xc8)
#define dbl_lower_right_corner char(0xbc)
#define dbl_horizontal_bar char(0xcd)
#define dbl_vertical_bar char(0xba)
#define upper_dbl_horizontal_vertical char(0xd1) // NOT IN USE!
#define lower_dbl_horizontal_vertical char(0xcf) // NOT IN USE!
#define left_dbl_vertical_horizontal char(0xc7) // NOT IN USE!
#define right_dbl_vertical_horizontal char(0xb6) // NOT IN USE!
#define cross_bar char(0xc5)
#define horizontal_bar char(0xc4)
#define vertical_bar char(0xb3)
void m_sheet (int x = 5, int y = 5, int interval = 10); // Declared functions
int main (void)
{
bool exit_code = false; // Initialize variables
std::string command;
std::cout << "\\n\\tThe Black Box a1.1\\n\\n\\tType ? to get help\\n"; // Print title
do { // Looping consol input while exit_code == false
std::cout << "\\n>"; // Generating consol input
std::getline (std::cin, command);
std::cout << "\\n\\n";
if (command == "0") exit_code = true; // Exit program
else if (command == "?") { // Generating help frame
std::string bar = "";
for (int i = 1; i<=61; i++) bar += dbl_horizontal_bar;
std::cout << "\\n\\t" << dbl_upper_left_corner << bar << dbl_upper_right_corner;
std::cout << "\\n\\t" << dbl_vertical_bar << " ? - Help 0 - Exit " << dbl_vertical_bar;
std::cout << "\\n\\t" << dbl_vertical_bar << " 1 - Multiplication Sheet 5*5 2 - Multiplication Sheet x*y " << dbl_vertical_bar;
std::cout << "\\n\\t" << dbl_lower_left_corner << bar << dbl_lower_right_corner;
std::cout << "\\n";
}
else if (command == "1") m_sheet (); // Generating table 5*5 using m_sheet procedure
else if (command == "2") { // Generating tables x*y using m_sheet procedure
std::string ix = "0", iy = "0"; // Initialize variables
int intX = 0, intY = 0;
std::cout << "\\n\\tX> "; // Asking for input to x and y
std::getline (std::cin, ix);
std::cout << "\\n\\tY> ";
std::getline (std::cin, iy);
std::stringstream(ix) >> intX; // Putting string values into integer values
std::stringstream(iy) >> intY;
if (intX > 1 && intY > 1) m_sheet (intX, intY); // Calling m_sheet procedure if no error
else std::cout << "\\n\\tFailure, x and y have to be any number above 0!\\n"; // If error print errormessage
}
} while (exit_code != true);
return 0; // Ending program with code 0x0
}
void m_sheet (int x, int y, int interval) // Procedure to generate multiplication sheet
{
std::string dbl_horizontal, single, dbl_upper, dbl_lower; // Initialize variables
int r, times, mod, xt = interval;
times = x / interval; // Set values of variables
mod = x % interval;
if (mod > 0) times += 1;
for (int i = 1; i <= times; i++) { // Loop(i) generating frame for tables x times
dbl_horizontal = ""; // Resetting values
single = "";
dbl_upper = "";
dbl_lower = "";
if (i == times) if (mod != 0) xt = mod; // Set value of width of table
for (int j = 1; j <= (5*xt+1); j++) { // Loop(j) generating frames
dbl_horizontal += dbl_horizontal_bar; // Set variables depending on rules
if (i == 1) {
if (j != 6) single += horizontal_bar;
else single += cross_bar;
}
else single += horizontal_bar;
} // Ending loop(j)
single = dbl_vertical_bar + single + dbl_vertical_bar; // Finishing frames
dbl_upper = dbl_upper_left_corner + dbl_horizontal + dbl_upper_right_corner;
dbl_lower = dbl_lower_left_corner + dbl_horizontal + dbl_lower_right_corner;
std::cout << "\\t" << dbl_upper; // Printing top of frame for each table
for (int b = 1; b <= y; b++) { // Loop(b) for printing vertical
std::cout << "\\n\\t" << dbl_vertical_bar; // Printing vertical dbl bar for each start of line
for (int a = 1; a <= xt; a++) { // Loop(a) for printing horizontal
r = ((i-1)*interval+a)*b; // Set variable(r)
if (r < 10) std::cout << " " << r << " "; // Rules on how to print numbers
else if (r > 9 && r < 100) std::cout << " " << r << " ";
else if (r > 99 && r < 1000) std::cout << " " << r << " ";
else std::cout << " ";
if (a == 1 && i == 1) std::cout << vertical_bar; // if (i == 1) divide first and second number in each line
else if (a == 1) std::cout << " ";
} // Ending loop(a)
std::cout << dbl_vertical_bar; // Printing vertical dbl bar for each end of line
if (b == 1) std::cout << "\\n\\t" << single; // if (b == 1) divide first and second line in each table
} // Ending loop(b)
std::cout << "\\n\\t" << dbl_lower << "\\n"; // Printing lower buttom of frame of each
} // Ending loop(i)
}
På forhånd tak og er modtagelig over for kritik....
Indlæg senest redigeret d. 11.05.2008 14:20 af Bruger #13737