#include
#include
#include
using namespace std;
// Function to get number of rows and columns
void getTableDimensions(int& rows, int& cols) {
cout << "Enter the number of columns: ";
cin >> cols;
cout << "Enter the number of rows: ";
cin >> rows;
}
// Function to get table data
vector> getTableData(int rows, int cols) {
vector> table(rows, vector(cols));
cout << "Enter the table data (headers in the first row):\n";
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
cout << "Enter data for cell [" << i + 1 << "][" << j + 1 << "]: ";
cin >> ws;
getline(cin, table[i][j]);
}
}
return table;
}
// Function to generate HTML content
string generateHTMLContent(const vector>& table, int rows, int cols) {
string htmlContent = R"(
HTML Table
)";
for (int i = 0; i < rows; i++) {
htmlContent += " \n";
for (int j = 0; j < cols; j++) {
if (i == 0)
htmlContent += " " + table[i][j] + " | \n";
else
htmlContent += " " + table[i][j] + " | \n";
}
htmlContent += "
\n";
}
htmlContent += R"(
)";
return htmlContent;
}
int main() {
int rows, cols;
// Step a & b
getTableDimensions(rows, cols);
// Step c
vector> table = getTableData(rows, cols);
// Step d
string htmlContent = generateHTMLContent(table, rows, cols);
// Step e (for online use: just print the HTML)
cout << "\n\n==== COPY THIS HTML CODE BELOW ====\n\n";
cout << htmlContent << endl;
return 0;
}