Ask Computer Engineering Expert

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!!!: 

:
-o  

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.

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M91246952

Have any Question?


Related Questions in Computer Engineering

Does bmw have a guided missile corporate culture and

Does BMW have a guided missile corporate culture, and incubator corporate culture, a family corporate culture, or an Eiffel tower corporate culture?

Rebecca borrows 10000 at 18 compounded annually she pays

Rebecca borrows $10,000 at 18% compounded annually. She pays off the loan over a 5-year period with annual payments, starting at year 1. Each successive payment is $700 greater than the previous payment. (a) How much was ...

Jeff decides to start saving some money from this upcoming

Jeff decides to start saving some money from this upcoming month onwards. He decides to save only $500 at first, but each month he will increase the amount invested by $100. He will do it for 60 months (including the fir ...

Suppose you make 30 annual investments in a fund that pays

Suppose you make 30 annual investments in a fund that pays 6% compounded annually. If your first deposit is $7,500 and each successive deposit is 6% greater than the preceding deposit, how much will be in the fund immedi ...

Question -under what circumstances is it ethical if ever to

Question :- Under what circumstances is it ethical, if ever, to use consumer information in marketing research? Explain why you consider it ethical or unethical.

What are the differences between four types of economics

What are the differences between four types of economics evaluations and their differences with other two (budget impact analysis (BIA) and cost of illness (COI) studies)?

What type of economic system does norway have explain some

What type of economic system does Norway have? Explain some of the benefits of this system to the country and some of the drawbacks,

Among the who imf and wto which of these governmental

Among the WHO, IMF, and WTO, which of these governmental institutions do you feel has most profoundly shaped healthcare outcomes in low-income countries and why? Please support your reasons with examples and research/doc ...

A real estate developer will build two different types of

A real estate developer will build two different types of apartments in a residential area: one- bedroom apartments and two-bedroom apartments. In addition, the developer will build either a swimming pool or a tennis cou ...

Question what some of the reasons that evolutionary models

Question : What some of the reasons that evolutionary models are considered by many to be the best approach to software development. The response must be typed, single spaced, must be in times new roman font (size 12) an ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As