473,499 Members | 1,576 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Little Help

35 New Member
I'm suppose to write two codes....I have some of it done, I don't think I've done it right.

I'm suppose to write a program that will get from the user's keyboard one sets of numbers that will be read into two 2 dimensional arrays of size 4 by 3. Below is an example.

Array A
column 1 column 2 column 3
2 3 5
4 5 7
1 2 1
2 3 3

-Write a function that will add all of the numbers in the array and reutrn only the sum to the main.
-Print out the array and the sum.
-Use at least three functions.
This is what I have so far.....
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2.  
  3. typedef int ar_t [3][4];
  4.  
  5. //! Enter array from user.
  6. //! Return by reference array of enter.
  7. void
  8. enter_array( ar_t & array ) {
  9.  
  10.     std::cout << "Enter array 3x4." << std::endl;
  11.  
  12.     // Proc all elements.
  13.     for( int i = 0; i < 3; ++i )
  14.         for( int j = 0; j < 4; ++j ) {
  15.  
  16.             std::cout << "[" << i+1 << "," << j+1 << "]:";
  17.  
  18.             std::cin >> array[i][j];
  19.  
  20.         }    
  21.  
  22.     return;
  23. }
  24.  
  25. //! Print array.
  26. void
  27. print_array( ar_t & array ) {
  28.  
  29.     std::cout << "Array 3x4." << std::endl;
  30.  
  31.     // Proc all elements.
  32.     for( int i = 0; i < 3; ++i ) {
  33.  
  34.         for( int j = 0; j < 4; ++j ) {
  35.             std::cout << array[i][j] << "\t";
  36.         }
  37.  
  38.         std::cout << std::endl;
  39.     }
  40.  
  41.     return;
  42. }
  43.  
  44. //! Calc sum of array.
  45. int
  46. calc_sum( ar_t & array ) {
  47.  
  48.     // Sum element.
  49.     int sum = 0;
  50.  
  51.     // Proc all elements.
  52.     for( int i = 0; i < 3; ++i )
  53.         for( int j = 0; j < 4; ++j ) 
  54.             sum += array[i][j];
  55.  
  56.     return sum;
  57. }
  58.  
  59. int main(int argc, char* argv[])
  60. {
  61.  
  62.     ar_t array;
  63.  
  64.     enter_array(array);
  65.  
  66.     print_array(array);
  67.  
  68.     std::cout << "Sum of array:" << calc_sum(array) << std::endl;
  69.  
  70.     return 0;
I'm suppose to write a program that will get from the user's keyboard two sets of numbers that will be read into two 2 dimensional arrays of size 4 by 3. Below is an example.

Array A
2 3 5
4 5 7
1 2 1
2 3 3

Array B
4 4 4
2 3 4
1 2 1
8 9 8

program will use at least three functions to:

-Take the two arrays and generate a third array whose elements are the sum of the corresponding elements of the first two arrays then print both array and the array containing the sum print them one after the other on a column

This is what I have so far
Expand|Select|Wrap|Line Numbers
  1.  #include <iostream>
  2.  
  3. // Array type for all arrays of task.
  4. typedef int ar_t [3][4];
  5.  
  6. //! Enter array from user.
  7. //! Return by reference array of enter.
  8. void
  9. enter_array( ar_t & array ) {
  10.  
  11.     std::cout << "Enter array 3x4." << std::endl;
  12.  
  13.     // Proc all elements.
  14.     for( int i = 0; i < 3; ++i )
  15.         for( int j = 0; j < 4; ++j ) {
  16.  
  17.             std::cout << "[" << i+1 << "," << j+1 << "]:";
  18.  
  19.             std::cin >> array[i][j];
  20.  
  21.         }    
  22.  
  23.     return;
  24. }
  25.  
  26. //! Print array.
  27. void
  28. print_array( ar_t & array ) {
  29.  
  30.     std::cout << "Array 3x4." << std::endl;
  31.  
  32.     // Proc all elements.
  33.     for( int i = 0; i < 3; ++i ) {
  34.  
  35.         for( int j = 0; j < 4; ++j ) {
  36.             std::cout << array[i][j] << "\t";
  37.         }
  38.  
  39.         std::cout << std::endl;
  40.     }
  41.  
  42.     return;
  43. }
  44.  
  45. //! Calc sum of array.
  46. int
  47. calc_sum( ar_t & array ) {
  48.  
  49.     // Sum element.
  50.     int sum = 0;
  51.  
  52.     // Proc all elements.
  53.     for( int i = 0; i < 3; ++i )
  54.         for( int j = 0; j < 4; ++j ) 
  55.             sum += array[i][j];
  56.  
  57.     return sum;
  58. }
  59.  
  60. //! Calc sum of two arrays into new array by all positions.
  61. void
  62. sum_two_arrays( ar_t & one, ar_t & two, ar_t & sum ) {
  63.  
  64.     // Proc all elements.
  65.     for( int i = 0; i < 3; ++i )
  66.         for( int j = 0; j < 4; ++j ) 
  67.             // sum all by index.
  68.             sum[i][j] = one[i][j] + two[i][j];
  69.  
  70.     return;    
  71. }
  72.  
  73. // Do all second task requements.
  74. void
  75. sum_of_two_arrays_by_user( ar_t & one, ar_t & two, ar_t & sum ) {
  76.  
  77.     // User enter first array.
  78.     std::cout << "Enter first array." << std::endl;
  79.     enter_array( one );
  80.  
  81.     // User enter second array.
  82.     std::cout << "Enter second array." << std::endl;
  83.     enter_array( two );
  84.  
  85.     // Forming array of sum.
  86.     sum_two_arrays( one, two, sum );
  87.  
  88.     // Print entered data.
  89.     std::cout << "Entered arrays is:" << std::endl;    
  90.     // First array.
  91.     print_array( one );
  92.     std::cout << std::endl;
  93.     // Second array.
  94.     print_array( two );
  95.     std::cout << std::endl;
  96.  
  97.     // Print result data.
  98.     std::cout << "Sum of entered arrays is:" << std::endl;
  99.  
  100.     // Print sum array.
  101.     print_array( sum );
  102.  
  103. }
  104.  
  105. void
  106. do_second_task() {
  107.  
  108.     // first array.
  109.     ar_t one;
  110.  
  111.     // second array.
  112.     ar_t two;
  113.  
  114.     // array of sum.
  115.     ar_t sum;
  116.  
  117.     sum_of_two_arrays_by_user( one, two, sum );
  118.  
  119. }
  120.  
  121. int main(int argc, char* argv[])
  122. {
  123.     // Do task function.
  124.     do_second_task();
  125.  
  126.     return 0;
  127. }
Nov 30 '06 #1
5 1313
Ganon11
3,652 Recognized Expert Specialist
OK, at first glance this looks fine. What problems are you getting?
Nov 30 '06 #2
05l8kr
35 New Member
OK, at first glance this looks fine. What problems are you getting?
Just doesn't seem right. It won't compile either, any explaination, why it won't compile?
Nov 30 '06 #3
Ganon11
3,652 Recognized Expert Specialist
Well, when you try to compile, what does it say? What errors are generated?

Posting these helps readers focus on the problem you're having, rather than having to meticulously go through every single line of code.
Nov 30 '06 #4
05l8kr
35 New Member
I'm I doing the void main correctly?
Dec 1 '06 #5
05l8kr
35 New Member
? void man correctly? anyone
Dec 2 '06 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
3409
by: Ron Stephens | last post by:
I posted to my web site a fun little program called merlin.py today. Please keep in mind that I am a hobbyist and this is just a little hack, if you look at the code you will see that it is still...
2
28994
by: hicham | last post by:
Hi, I am looking for help, i would like to know how can i use the endian.h and config.h to convert compiled files under solaris from BIG-ENDIAN to compiled files LITTLE-ENDIAN. I am working...
2
2162
by: OZ | last post by:
Hi, I am new C++ and need a little help with a public domain program that is suppose to perform a byte swap. I am receiving the following error messages during the compile process with Microsoft...
2
1515
by: | last post by:
Hi, Im kindof new to c++... need a little help with system() function.. I use system to execute a dos program... but i want the rest of the program to continue imediately after executing it. and...
3
1433
by: Erik Thorsen | last post by:
Hello! I am in the process of creating a database listing tours, something similar to what you can find on www.infohub.com. This means that I need to create a database which can be searchable...
8
27435
by: Perception | last post by:
Hello all, If I have a C-like data structure such that struct Data { int a; //16-bit value char; //3 ASCII characters int b; //32-bit value int c; //24-bit value }
2
2036
by: Daniel | last post by:
I'm new to .Net and all of its abilities so I hope this makes sense. Basically I'm confused on when is the appropriate time to use web forms controls vs. regular HTML. For example in ASP...
14
1819
by: Brett Sinclair | last post by:
Hello everybody I'm still on the learning curve here...and from what I read, I created inherited datagrid class so I could have icons, combobox...etc in the columns of my datagrid. The grid...
16
2382
by: Durumdara | last post by:
Hi ! I have a problem. I have a little tool that can get data about filesystems and wrote it in python. The main user asked me a GUI for this software. This user is needed a portable...
0
1032
by: nintesa | last post by:
Hello from Italy! I'm trying to create a little script (php/mysql/javascript) to record visits of some of my sites. I have sites www.a.com, www.b.com ecc... and I have my counter script on...
0
7132
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7223
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5475
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4602
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3103
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3094
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.