copy array

how to declare another array(bigger), copy 1st array into it, then copy 2nd array after that, continue from the last item of array 1, not to replace them.
Then sort array3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
using namespace std;
int main()
{
	
float mark [10];

for ( int i=0; i<=9; i++)
 {
 cout << " marks assignment in tutorial 1 for student no_" << i+1<< ": " <<"\n";
    cin >>  mark [i];
 }
  float mark2  [8];
  for ( int i=0; i<=7; i++)
 {
 cout << " marks assignment in tutorial 2 for student no_" << i+1<< ": " <<"\n";
    cin >>  mark2 [i];
    
    
    
  }
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
#include <algorithm>

int main()
{
    const int N1 = 5, N2 = 7, NBIG = 100 ;
    static_assert( NBIG >= (N1+N2), "target array is too small" ) ;

    const int first[N1] = { 20, 1, 22, 3, 24 } ;
    const int second[N2] = { 65, 6, 57, 8, 49, 10, 31 } ;

    {
        int big[NBIG] = {} ;
        
        // http://en.cppreference.com/w/cpp/algorithm/copy
        const auto end = std::copy( second, second+N2, std::copy( first, first+N1, big ) ) ;
        
        // http://en.cppreference.com/w/cpp/algorithm/sort
        std::sort( big, end ) ;

        for( auto ptr = big ; ptr != end ; ++ptr ) std::cout << *ptr << ' ' ;
        std::cout << '\n' ;
    }

    {
        int big[NBIG] = {} ;

        // copy one by one
        auto end = std::copy( first, first+N1, big ) ;
        end = std::copy( second, second+N2, end ) ;
        
        std::sort( big, end ) ;

        for( auto ptr = big ; ptr != end ; ++ptr ) std::cout << *ptr << ' ' ;
        std::cout << '\n' ;
    }
}

http://coliru.stacked-crooked.com/a/5e2014697c27d828
Topic archived. No new replies allowed.