The program needs to read the number of rows and columns

Assignment Help Basic Computer Science
Reference no: EM13707536

can any one help me with this c++ program?

create a two dimension alarray of structs that contain the multiplication and division table of the rows and columns, starting at 1 instead of zero. This prevents us from causing a divide by zero error in the division table!

The program needs to read the number of rows and columns from the user as command line arguments. You do need to check if the user supplied a number before you convert the string to a number. Continue to prompt for correct values, if the number isn't a valid, non-zero integer. At the end of the program, prompt the user if he/she wants to see this information for a different size matrix. Make sure you do not have a memory leak!!!!

//Checked that rows and cols are valid, non-zero integers rows=atoi(argv[1]); cols=atoi(argv[2]);

For example, if you run your program with these command line arguments:

./prog 5 5

Your program should create a 5 by 5 matrix of structs and assign the multiplication table to the mult variable in the struct and the division of the indices to the div variable in the struct. The mult variable is an integer, and the div variable needs to be a float (or double).

struct mult_div_values { int mult;

float div; };

Your program needs to be well modularized with functions, including main, with 10 or less lines of code. This means you will have a function that checks if the rows and cols are valid, non-zero integers, bool is_valid_diminsions(char *m, char *n), and another function that creates the matrix of structs given the m x n dimensions, mult_div_values** create_table(int m, int n). In addition, you need to have functions that set the multiplication and division values, as well as delete your matrix from the heap:

void set_mult_values(mult_div_values **table, int m, int n) void set_div_values(mult_div_values **table, int m, int n) void delete_table(mult_div_values ***table, int m)

Then, call functions to print the tables. Example: ./prog 5 t You did not input a valid column.
Please enter an integer greater than 0 for a column:

5 Multiplication Table:

1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25

Division Table:
1.00   0.50 0.33 .025   0.20

2.00 1.00 0.67 0.50 0.40

3.00 1.50 1.00 0.75 0.60

4.00 2.00 1.33 1.00 0.80

5.00 2.50 1.67 1.25 1.00

Would you like to see a different size matrix (0-no, 1-yes)? 0

begin making an interface file that holds all this information for us.

Create a mult_div.h interface file that will contain all the function and struct declaration information we need:

struct mult_div_values { int mult;

float div; };

bool is_valid_diminsions(char *m, char *n); mult_div_values** create_table(int, int);
void set_mult_values(mult_div_values **, int, int); void set_div_values(mult_div_values **, int, int); void delete_table(mult_div_values ***table, int m);

Now, compile your program normally: g++ mult_div.cpp -o mult_div

Let's take this a step further, and keep only your function definitions in this implementation file, i.e. mult_div.cpp, and put your main function in a separate implementation file called prog.cpp. Your prog.cpp file will have to include the mult_div.h file too.

After creating this file, then you can include it into your implementation, .cpp file, and remove these prototypes and struct definition from your file.

#include "./mult_div.h"

Now, compile your program normally: g++ mult_div.cpp -o mult_div 

Let's take this a step further, and keep only your function definitions in this implementation file, i.e. mult_div.cpp, and put your main function in a separate implementation file called prog.cpp. Your prog.cpp file will have to include the mult_div.h file too. But, now how do we put these two files together? We have to compile them together, i.e. g++ mult_div.cpp prog.cpp -o mult_div 

What if we had 1,000 implementation (.cpp) files? We do not want to do this manually anymore, right? There is a built-in UNIX/Linux script that makes this easy! This is called a Makefile. Just vim Makefile to create it. Now, add the following to the file with the spacing being a tab!!!: 

<target>:
<compiler> <file1.cpp> <file2.cpp> -o <target> 

Example: 

mult_div:
g++ mult_div.cpp prog.cpp -o mult_div 

Now, save and exit the file. You can type make in the terminal to now run this file.

Reference no: EM13707536

Questions Cloud

How long is the flea in the air from the time : A flea jumps straight up to a maximum height of 0.360m. How long is the flea in the air from the time it jumps to the time it hits the ground
What would be the braking distance : A car traveling at a speed of v can brake to an emergency stop in a distance x. What would be the braking distance if the car were traveling at 60.0km/h
Find the tension in each part of the rope : A piñata of mass M = 6.7 kg is attached to a rope of negligible mass that is strung between the tops of two vertical poles. Find the tension (T) in each part of the rope due to the weight of the piñata
How long does the bullet take to pass through it : A bullet traveling horizontally at a speed of 330m/s hits a board perpendicular to its surface, how long does the bullet take to pass through it
The program needs to read the number of rows and columns : The program needs to read the number of rows and columns from the user as command line arguments. You do need to check if the user supplied a number before you convert the string to a number. Continue to prompt for correct values, if the number..
Find what is the bullet time of flight : A rifle is aimed horizontally at a target 35 m away. The bullet hits the target 2.8 cm below the aiming point. What is the bullet's time of flight
What is the speed of the car at the end of that time : A car accelerates from rest at a constant rate of 2.4m/s2 for 5.0s. What is the speed of the car at the end of that time
Dna rights-who owns your genetic code : Research the history, examples, causes, impacts ancftthical issues surrounding the subject. Be sure to understand the arguments being used by all parties. There may be more than 2 sides of the issue.
What horizontal force is required to move the box : A 6.27kg box sits on a ramp that is inclined at 37.0 degrees above the horizontal. The coefficient of kinetic friction between the box and the ramp is 0.30. What horizontal force is required to move the box

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Create a communication diagram for the scenarios

Create a communication diagram for the scenarios

  How could those redundancies lead to anomalies

If you want to produce a listing of the file contents by last name, area code, city, state, or zip code, how would you alter the file structure?

  Explain why logic is an important part of oop

Logic is a key factor in laying out the processes for programming a game/application/website. Explain why logic is an important part of OOP.

  Adding fiber from the beginning

Adding fiber from the beginning.

  Apply the cartesian product construction

Apply the Cartesian product construction to (i) and (j) to obtain an automata recognizing the union of their languages. i. {w|w every odd position of w is a 1} j. {w| w contains at least two Os and at most one 1}

  Effective user-level thread implementation

What must a kernel provide for an effective user-level thread implementation? Do you have immediate help for this answer?

  Compare five technologies for in-home internet access

Compare and contrast at least five technologies which are readily available for in-home internet access. You must consider practical as well as technical differences in your comparison.

  Compare and contrast distance-vector and link state routing

Compare and contrast distance-vector and link state routing

  Your manager has decided that the throughput

Your manager has decided that the throughput of your file server can be improved by replacing your old SCSI-2 host adapter with a "fast and wide" SCSI-3 adapter. It has also been decided that the old SCSI-2 drives will be replaced with "fast and w..

  Draw a magenta circle

Given a graphics object g, write a few lines of code to have that graphics object draw a magenta circle (not filled in) that has a diameter of 200 pixels.

  Show layout of specified cache for cpu address memory

Show the layout of the specified cache for a CPU that can address 8M x 16 of memory. Give the layout of the bits per location and the total number of locations.

  Recursive multiplication

Recursive Multiplication Write a main program that uses a recursive function. This function accepts two arguments into the parameters x and y.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd