24.3k views
0 votes
I have this assignment due TONIGHT BEFORE 10PM! Please help. 50 points for whoever will help!! Here is the assignment.

Your program is to have a main() function which controls the program. Create two lists containing a number of random values from 1 to 10. Create a function to generate these lists. This function will have to be called twice from main(). Once for each list. The number of elements per list is to be input by the user, so pass that value into the generate list function as a parameter. Write two functions, one to add the two lists of corresponding values together and one to multiple the two lists of corresponding values and store the results in a new list. For adding, you take list1[0] and add it to list2[0], add list1[1] and list2[2] and so on for the number of elements in the list. For multiplying, take list1[0] and multiply it times list2[0] and so on for each element in the list and store this value in a new list. Create a displayList() function to display the four lists. Pass in a reference to the list which needs to be printed. Do this for all four lists. Format your output in aligned columns using the format specifier command.

1 Answer

3 votes

Answer:

# include <iostream.h>

# include <conio.h>

using namespace std;

int generatelist ( int z[]);

int addlist(int x []; int y []);

int mullist(int x []; int y []);

int displayList(int z[]);

main()

{

int a[10] , b[10], add[10], mul[10];

cout<<"Enter value in array a";

generatelist(a[10]);

cout<<"Enter value in array b";

generatelist(b[10]);

for (int i=0; i<=9; i++)

{

add[i]=addlist( a[i], b[i]);

cout<<"sum of list = "<< add[i];

}

for (int i=0; i<=9; i++)

{

mul[i]=mullist( a[i], b[i]);

cout<<"multiplication of list = "<< mul[i];

}

for (int i=0; i<=9; i++)

{

displayList(a[i]);

}

for (int i=0; i<=9; i++)

{

displayList(b[i]);

}

for (int i=0; i<=9; i++)

{

displayList(add[i]);

}

for (int i=0; i<=9; i++)

{

displayList(mul[i]);

}

getch();

}

int generatelist ( int z[])

{

for (int j=0 ; j<=9 ; j++)

{

cin>>z[j];

return z[j]

}

}

int addlist(int x []; int y [])

{

int add

add=x+y;

return add;

}

int mullist(int x []; int y [])

{

int mul

mul=x*y;

return mul;

}

int displayList(int z[]);

{

for(int i=0; i<=9;i++)

cout << z[i]

}

User FlorisdG
by
5.9k points