Kardeşimin ödevi için yardım - kod çalışmıyor

Durum
Üzgünüz bu konu cevaplar için kapatılmıştır...
Üye
Katılım
7 May 2021
Mesajlar
1
Tepki puanı
0
Yaş
28
5 HİZMET YILI
Beyler kardeşimin acil ödevi var saatlerdir urağşıyoruz ama kod bir türlü çalışmıyor bugün içinde teslim etmemiz gerekiyor lütfen yardım edin arkdaşlar

You're going to reverse each occurence of an array in a given 2D matrix.

This process will be applied to a number of integers,which should be stored in a two-dimensional array.

First,fill an integer table by calling fill_table function.This function should randomly fill the array with the integers between 1 and 9. The last element of the array should be equal to the 0.

Then, in the main program you should define an array which must exist in the table at least 1.After each occurrence of the array is dound and reversed in the table,the result should be printed by calling the print_table function.

All accesses must be done using pointers.You can assume that 2D matrix size is equal to 10 to 10.

void fill_table(int table[10][10]){} : This function is responsible for filling the table.The last element of the the table must be equal to 0.

void print_table(int table[10][10]{} : This function is responsible for printing all integers in the table.

int find_and_replace_array(int *array1,in
[02:09, 07.05.2021] Yıldız Ozan: int find_and_replace_array(int *array1,int *array2,int len1,int len2){} : This function finds all occurences of array2 in the array1 and calls the reverse function with appropriate parameters for them to be reversed. Note that the return type is "int" instead of "void". Use this to your advantage.

void reverse(int *array1,int position,int * array2, intlen2){} : This function is responsible for the reversing process itself. Here, it is guaranteed that there is an occurance of the array2 in the array1 at position index.

void find_and_replace_table(int table[10][10],int *array,int len1,int len2){} : This function reverses all occurrences of the array in all integers available in the table by calling appropriate functions.
bu en alttaki satırı yani

void find_and_replace_table(int table[10][10],int *array,int len1,int len2){} : This function reverses all occurrences of the array in all integers available in the table by calling appropriate functions.
bu satırıda yazanları bir türlü yapıp çalıştıramıyoruz son günü lütfen yardım edin arkdaşlar nasıl yapabiliriz

Bağlantıları görmek için lütfen Giriş Yap

Bağlantıları görmek için lütfen Giriş Yap

ödevin resmide bu arkdaşlar
 

BOT

hellö
Ultra Üye
Katılım
3 Şub 2016
Mesajlar
1,842
Çözümler
53
Tepki puanı
688
Ödüller
11
10 HİZMET YILI
Ödevi açıklayın yardımcı olalım.
 
Słyszę, słyszę letni powiew.
Kurucu
Katılım
20 Haz 2015
Mesajlar
7,666
Çözümler
136
Tepki puanı
20,725
Ödüller
25
10 HİZMET YILI
C mi C++ mı olduğunu belirtmemişsin..
C++:
// ConsoleApplication1.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>

void fill_table(int table[10][10]) { 
    std::cout << "before";
    srand(time(NULL));
    for (size_t i = 0; i < 10; i++)
    {
        for (size_t y = 0; y < 10; y++)
        {   
            int iRand = (rand() % 9) + 1;
            if (i != 9 || y != 9)
                table[i][y] = iRand;
            else
                table[i][y] = 0;
        }
    }
}
void print_table(int table[10][10]) {
    for (size_t i = 0; i < 10; i++)
    {
        printf("\n");
        for (size_t y = 0; y < 10; y++)
        {
            printf("%d ", table[i][y]);
              
        }
    }
}

void reverse(int* array1,int position, int* array2, int len2) {
    for (int i = len2-1; i >= 0; i--)
    {
        static int y = 0;
        *(array1 + position + i) = *(array2 + y);
        y++;
      
    }
}
int find_and_replace_array(int* array1, int* array2, int len1, int len2) {
 
    bool isMatched = false;
    int matched_index = 0;
    for (size_t i = 0; i < len1; i++)
    {
      
        auto arr1_line = array1+i;
        for (size_t y = 0; y < len2; y++)
        {
            if (isMatched)
            break;
            
            if (*(arr1_line + y) != *(array2 + y))
            break;
    

            if (y == (len2 - 1))
            isMatched = true;
        
        }   
        if (isMatched) {
            //printf("Matched index at %d = ", i);
            //for (size_t z = 0; z < len2; z++)
            //printf("%d ", *(arr1_line + z));
            reverse(array1, i, array2, len2);
            return 1;
        }
    }
    return 0;
}

template <size_t size_x, size_t size_y>
int sizeof_2DArray(int(&arr)[size_x][size_y])
{
    int rows = sizeof arr / sizeof arr[0];
    int cols = sizeof arr[0] / sizeof(int);
    return rows * cols;
    
}

int main()
{
    int Array[10][10];
    fill_table(Array);
    print_table(Array);
    int* pArray = (int*)Array;
    int len_Array = sizeof_2DArray(Array);
    std::cout << "\n \n Please write the array without any spaces which you want to find and reverse in the array table: \n";
    char Arr_1[11]; int tempArr[10];
    std::cin.getline(Arr_1, 11);
    for (size_t i = 0; i < 10; i++)
    {
        if (Arr_1[i] != '\0' && Arr_1[i] != '0')
            tempArr[i] = Arr_1[i] - '0';
        else
            tempArr[i] = 0;
    }
    int len_tempArray = sizeof(tempArr) / sizeof(tempArr[0]);
    int* pTempArray = (int*)tempArr;
    if(find_and_replace_array(pArray, pTempArray, len_Array, len_tempArray)){
        std::cout << "\nafter";
        print_table(Array);
    }
    else {
        std::cout << "No Match Found !";
    }
}
 

Ekli dosyalar

  • 1620381164724.png
    1620381164724.png
    8.3 KB · Görüntüleme: 60
Son düzenleme:
Üye
Katılım
7 May 2021
Mesajlar
1
Tepki puanı
0
Yaş
29
5 HİZMET YILI
C mi C++ mı olduğunu belirtmemişsin..
C++:
// ConsoleApplication1.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>

void fill_table(int table[10][10]) {
    std::cout << "before";
    srand(time(NULL));
    for (size_t i = 0; i < 10; i++)
    {
        for (size_t y = 0; y < 10; y++)
        {  
            int iRand = (rand() % 9) + 1;
            if (i != 9 || y != 9)
                table[i][y] = iRand;
            else
                table[i][y] = 0;
        }
    }
}
void print_table(int table[10][10]) {
    for (size_t i = 0; i < 10; i++)
    {
        printf("\n");
        for (size_t y = 0; y < 10; y++)
        {
            printf("%d ", table[i][y]);
             
        }
    }
}

void reverse(int* array1,int position, int* array2, int len2) {
    for (int i = len2-1; i >= 0; i--)
    {
        static int y = 0;
        *(array1 + position + i) = *(array2 + y);
        y++;
     
    }
}
int find_and_replace_array(int* array1, int* array2, int len1, int len2) {

    bool isMatched = false;
    int matched_index = 0;
    for (size_t i = 0; i < len1; i++)
    {
     
        auto arr1_line = array1+i;
        for (size_t y = 0; y < len2; y++)
        {
            if (isMatched)
            break;
           
            if (*(arr1_line + y) != *(array2 + y))
            break;
   

            if (y == (len2 - 1))
            isMatched = true;
       
        }  
        if (isMatched) {
            //printf("Matched index at %d = ", i);
            //for (size_t z = 0; z < len2; z++)
            //printf("%d ", *(arr1_line + z));
            reverse(array1, i, array2, len2);
            return 1;
        }
    }
    return 0;
}

template <size_t size_x, size_t size_y>
int sizeof_2DArray(int(&arr)[size_x][size_y])
{
    int rows = sizeof arr / sizeof arr[0];
    int cols = sizeof arr[0] / sizeof(int);
    return rows * cols;
   
}

int main()
{
    int Array[10][10];
    fill_table(Array);
    print_table(Array);
    int* pArray = (int*)Array;
    int len_Array = sizeof_2DArray(Array);
    std::cout << "\n \n Please write the array without any spaces which you want to find and reverse in the array table: \n";
    char Arr_1[11]; int tempArr[10];
    std::cin.getline(Arr_1, 11);
    for (size_t i = 0; i < 10; i++)
    {
        if (Arr_1[i] != '\0' && Arr_1[i] != '0')
            tempArr[i] = Arr_1[i] - '0';
        else
            tempArr[i] = 0;
    }
    int len_tempArray = sizeof(tempArr) / sizeof(tempArr[0]);
    int* pTempArray = (int*)tempArr;
    if(find_and_replace_array(pArray, pTempArray, len_Array, len_tempArray)){
        std::cout << "\nafter";
        print_table(Array);
    }
    else {
        std::cout << "No Match Found !";
    }
}
C dili ile nasıl yapılabilir acaba
 
Durum
Üzgünüz bu konu cevaplar için kapatılmıştır...
Üst