Question

(Written in C++) Your assignment is to generate an HTML multiplication table with dimensions specified by...

(Written in C++) Your assignment is to generate an HTML multiplication table with dimensions specified by the user. You will ask the user for the number of rows then number of columns, and generate an HTML table of the appropriate size. The top left cell should contain the result of 1 x 1, and the bottom right cell should contain the result of num_rows x num_cols.

Each row and column may be an integer value between 1 and 12 inclusive (1 or 12 are valid). If the user does not specify a value in this range or a value that is not a valid integer, prompt the user again until you receive a valid value. You should not simply exit the program if invalid input is given.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

Note: You can add more formatting options like background color, cell width, styling etc as you wish. Right now, this will just create a basic html file with a table containing multiplication table of specified number of rows and columns.

#include<iostream>

#include<fstream>

using namespace std;

//helper method to get a valid integer between 1 and 12

int getInput(string prompt){

                int value=0;

                //looping until user enter valid value

                while(value<1 || value>12){

                                cout<<prompt;

                                cin>>value;

                                //checking if read value is not an integer (reading failed), or value is not in proper range

                                if(cin.fail() || value<1 || value>12){

                                                //clearing input buffer to remove any stray input

                                                cin.clear();

                                                cin.sync();

                                                //displaying error message

                                                cout<<"Error! The value should be between 1 and 12. Try again."<<endl;

                                }

                }

                //returning validated value

                return value;

}

int main(){

                //using the helper method, reading number of rows and columns

                int rows=getInput("Please enter the number of rows: ");

                int cols=getInput("Please enter the number of columns: ");

               

                //creating a file named output.html, change file name if you want

                ofstream outFile("output.html");

               

                //writing html opening tags to set up an html page with a table

                //using a 1px border and occuppying half of the window (50%)

                outFile<<"<html>\n<body>\n<table border=\"1\" style=\"width:50%\">\n";

                //looping through each row value

                for(int i=1;i<=rows;i++){

                                //writing row opening tag

                                outFile<<"<tr>";

                                //looping through each column

                                for(int j=1;j<=cols;j++){

                                                //finding current value

                                                int value=i*j;

                                                //writing to the file within a pair of <td> </td> tags

                                                outFile<<"<td>"<<value<<"</td> ";

                                }

                                //closing the row tag

                                outFile<<"</tr>\n";

                }

                //closing the table, body and html tags

                outFile<<"</table>\n</body>\n</html>";

                //closing file, saving changes, alerting user

                outFile.close();

                cout<<"The resultant table has been stored in output.html, please check"<<endl;

                return 0;

}

/*OUTPUT*/

Please enter the number of rows: -2

Error! The value should be between 1 and 12. Try again.

Please enter the number of rows: 0

Error! The value should be between 1 and 12. Try again.

Please enter the number of rows: 5

Please enter the number of columns: 10

The resultant table has been stored in output.html, please check

//output.html generated


Add a comment
Know the answer?
Add Answer to:
(Written in C++) Your assignment is to generate an HTML multiplication table with dimensions specified by...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • use Quincy Write a program to generate the multiplication table of an integer number (entered by...

    use Quincy Write a program to generate the multiplication table of an integer number (entered by the user) using for loop. You should only use the main() function. Sample output Enter an integer: 9 9*1=9 9*2=18 9*3=27 9*4=36 9*5=45 9*6=54 9*7=63 9*8=72 9*9=81 9*10=90

  • This is a quick little assignment I have to do, but I missed alot of class...

    This is a quick little assignment I have to do, but I missed alot of class due to the Hurricane and no one here knows what theyre doing. please help! this is Java with intelli-J Overview In this project students will build a four-function one-run calculator on the command line. The program will first prompt the user for two numbers, then display a menu with five operations. It will allow the user to select an option by reading input using...

  • Please help me out with this assignment. Please read the requirements carefully. And in the main...

    Please help me out with this assignment. Please read the requirements carefully. And in the main function please cout the matrix done by different operations! Thanks a lot! For this homework exercise you will be exploring the implementation of matrix multiplication using C++ There are third party libraries that provide matrix multiplication, but for this homework you will be implementing your own class object and overloading some C+ operators to achieve matrix multiplication. 1. 10pts] Create a custom class called...

  • Choose 3 of 5 Problems to Solve Need Soon as possible Choose 3 of5 Problems to...

    Choose 3 of 5 Problems to Solve Need Soon as possible Choose 3 of5 Problems to Solve (20 Point/Each) Problem l: Triangle Printing Program: Write an application that prints a right triangle with 1 to 8 rows. Prompt the user to enter an odd number in the range of 1 to 8 to specify the number of rows in the diamond. Add a validation loop to ensure the user does not enter an even number or a number outside the...

  • 1. (30 Points) Write a MATLAB program that displays "The multiplication of 10 multiplied by integers...

    1. (30 Points) Write a MATLAB program that displays "The multiplication of 10 multiplied by integers of 1 through 15. Display your result back to the user with 2 decimal places (yes, 2 decimal places). You must implement your code using a for loop. The result should have the following format: The multiplication of 10*1 =10.00 The multiplication of 10*2 =20.00 The multiplication of 10'3=30.00 The multiplication of 10*15=150.00 2. (35 Points) Write MATLAB code to prompt a user for...

  • Using Html 5: - You are to create a table consisting of 11 rows and 11...

    Using Html 5: - You are to create a table consisting of 11 rows and 11 columns. The table cells are to be 40 pixels wide, each row. The table is to also have a header row that spans across all columns and contains 'Multiplication Math' as the table name. - Alternating rows will have a different background color. - The table is to be centered in the HTML page. The top table row is to have the numbers 1-10...

  • Write a calculator program using JavaScript in HTML in the same HTML file. (There will only...

    Write a calculator program using JavaScript in HTML in the same HTML file. (There will only be 1 HTML file containing everything that you use for this program.) *************JavaScript Functions should be written in the HTML <head> .............. </head> tag, **************** (Please be mindful of the formatting of the text of your program. Meaning that do not copy paste everything in a single line. Add clear comments for a better understanding of your program) as follows Assignment: create a form...

  • Using Python, Can someone please assist in the following: These are the hints: Summary This week's lab is to create a simple multiplication table using nested loops and if statements. Prompt the...

    Using Python, Can someone please assist in the following: These are the hints: Summary This week's lab is to create a simple multiplication table using nested loops and if statements. Prompt the user for the size of the multiplication table (from 2x2 to 10x10). Use a validation loop to display a warning if the number is less than 2 or greater than 10 and prompt the user to enter the data again until they enter a valid number Put a...

  • C++ programming For this assignment, write a program that will act as a geometry calculator. The...

    C++ programming For this assignment, write a program that will act as a geometry calculator. The program will be menu-driven and should continue to execute as long as the user wants to continue. Basic Program Logic The program should start by displaying a menu similar to the following: Geometry Calculator 1. Calculate the area of a circle 2. Calculate the area of a triangle 3. Quit Enter your choice(1-3): and get the user's choice as an integer. After the choice...

  • Write the Code in C program. Create a random password generator that contains a user-specified number...

    Write the Code in C program. Create a random password generator that contains a user-specified number of characters. Your program should prompt the user for the desired length of the password. Length of password: To create your password, use the random number generator in the stdlib.h C library. To generate random numbers, you will need the srand() and rand() functions. srand(seed) is used to "seed" the random number generator with the given integer, seed. Prompt the user for the seed...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT