Answer:
According to the given data, the following as the C++ code.
Code:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
//method to fill the even parity of rows
void even_parity_row(int *newArr, int m, int n)
{
for (int i = 0; i < m; i++)
{
int rowParity = 0;
int j;
for (j = 0; j < n; j++)
{
rowParity = rowParity + *(newArr + i*n + j);
}
if(rowParity%2==0)
*(newArr + i*n + j) = 1;
else
*(newArr + i*n + j) = 0;
}
}
//method to fill the even parity of columns
void even_parity_col(int *newArr, int m, int n)
{
for (int j = 0; j < m; j++)
{
int colParity = 0;
int i;
for (i = 0; i < n; i++)
{
colParity = colParity + *(newArr + i*n + j);
}
if(colParity%2==0)
*(newArr + i*n + j) = 1;
else
*(newArr + i*n + j) = 0;
}
}
//method to display the new array on the computer screen
void print_arrray(int *newArr, int m, int n)
{
for(int i=0; i<m+1; i++)
{
for(int j=0; j<n+1; j++)
{
cout<<*(newArr + i*n + j)<<" ";
}
cout<<endl;
}
}
int main()
{
int m = 3, n = 3;
int* arr = new int[m*n];
//initialize array with 0 and 1
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
*(arr + i*n + j) = rand() % 2;
}
}
int* newArr = new int[(m+1)*(n+1)];
// here initialize new array
for (int i = 0; i < m; i++)
{
int rowParity = 0;
int j;
for (j = 0; j < n; j++)
{
rowParity = rowParity + *(arr + i*n + j);
*(newArr + i*n + j) = *(arr + i*n + j);
}
}
//method calling
even_parity_row(newArr, m, n);
even_parity_col(newArr, m, n);
print_arrray(newArr, m, n);
return 0;
}
OUTPUT:
1 0 1 1
1 1 1 0
0 0 1 0
1 0 0 0
I hope it will be helpful, Please give ThumsUp
Thank you!!
in C++ Q5-pointers: Using pointer notation and dynamic array to: input m*n array of zeros and...
solve it in c+*
Part II: Dynamic Arrays and Pointer Arithmetic Q5: Implement a subset function for a dynamic array which returns a new dynamic array that is a subset of the original. (15pt) input parameters: array - (the array and any related parameters) start - index of the first element end - index of the last element This function returns a new dynamic array containing the elements from the start thru the end indices of the original array. All...
How to initialize a dynamic two-dimensional array with values? (C++) Here's my problem... # include using namespace std; int main() { // Q#5 - dynamic 2d arrays, indexing via subscript operator, pointer arithmetic // tic tac toe board is an array of int pointers // each int pointer in the board points to a row // declare a pointer to an array of int pointers (i.e. a pointer to a pointer of type int) const...
Rewrite the program you submitted for A8 to use pointers, pointer notation and arithmetic, etc. as follows: If you did not complete A8, you will need to start with those instructions, and then, change your code based on the instructions here The main() function should: Create a fixed or dynamic array, e.g., double grade[SIZE] or double *grade = malloc(...) or calloc(...) Concerning the function call for getData(), pass the address of the array and its size to pointers; depending on...
Write in C code: Define an array f=[23,-12,34,-56,-10,12,19], using call-by-reference (use pointers), to pass the array to a function, named Summation. In main: Define array, pass array, print out the array and the result returned from Summation on screen. In function Summation: 1)take array and size from main 2) sum each element according to the following rules 3) if the value of f(i) is positive, add 2*f(i) to the sum 4)if the value of f(i) is negative, add -3*f(i) to...
1. Write a C++ Program to display address of elements of an array using both array and pointers 2. Write a C++ Program to insert and display data entered by using pointer notation. 3. Write a C++ Program to access Array Elements Using Pointer
Hello I need help with this program. Should programmed in C!
Program 2: Sorting with Pointers Sometimes we're given an array of data that we need to be able to view in sorted order while leaving the original order unchanged. In such cases we could sort the data set, but then we would lose the information contained in the original order. We need a better solution. One solution might be to create a duplicate of the data set, perhaps make...
C programming. 1.Create a program that does the following - Creates three pointers, a character pointer professor, and two integer pointers student_ids, grades - Using dynamic memory, use calloc to allocate 256 characters for the professor pointer - Prompts the professor for their name, and the number of students to mark. - Stores the professor’s name using the professor pointer and in an integer the number of students to mark. - Using dynamic memory, use malloc to allocate memory for...
Write the following program in C++. Review structures, pointers and dynamic memory allocation from CSIT 839. Also, review pointers and dynamic memory allocation posted here under Pages. For sorting, you can refer to the textbook for Co Sci 839 or google "C++ sort functions". I've also included under files, a sample C++ source file named sort_binsearch.cpp which gives an example of both sorting and binary search. The Bubble sort is the simplest. For binary search too, you can refer to...
need question 3 assap using cin and cout outputs please
Ctrl CSC 270 Final Exam-Spring2 1) [10 pts] Create anarray x which includes integers fron ltos obtain the array y which, even formula. Display both arrays x and y in a table with labeled column headings. 0 y- 2x+1 2) 120 pts] Consider the following 2D array. 01 2 -1 X-3 5 0 6 -3 7 -15 Use the standard notation and obtain the following (a) Create and display array...
IN C++ ADD COMMENTS AS MUCH AS POSSIBLE Exercise 1: Duplicate the Arrays Suppose you are developing a program that works with arrays of integers, and you find that you frequently need to duplicate the arrays. Rather than rewriting the array-duplicating code each time you need it, you decide to write a function that accepts an array and its size as arguments. Creates a new array that is a copy of the argument array, and returns a pointer to the...