+1 (315) 557-6473 

Create a Program to Implement Arrays in C++ Assignment Solution.


Instructions

Objective
Write a C++ assignment program to implement arrays in .

Requirements and Specifications

program to implement arrays in c assignment solution
program to implement arrays in c assignment solution 1

Source Code

#include

#include

#include

// A.

bool checkDuplicates(int arr[], int n, int k)

{

for (int i = 0; i < n; i++) {

int j = i + 1;

int range = k;

while (range > 0 && j < n) {

if (arr[i] == arr[j])

return true;

j++;

range--;

}

}

return false;

}

// B.

void white_black(int pixels[][5], int rows){

int r, c;

for(r=0; r<5; r++){

for(c=0; c<5; c++){

pixels[r][c] = 255 - pixels[r][c];

}

}

for(r=0; r<5; r++){

for(c=0; c<5; c++){

printf("%4d",pixels[r][c]);

}

printf("\n");

}

}

int main()

{

// A.

int arr[10];

for(int i = 0; i< 10; ++i) {

printf("Input number %d:",i+1);

scanf("%d", &arr[i]);

}

int n = sizeof(arr) / sizeof(arr[0]);

if (checkDuplicates(arr, n, 3))

printf("There are duplicate values \n");

else

printf("There are not duplicate values \n");

printf("----------- \n");

// B.

int pix[5][5] = {

{183, 226, 180, 117, 222},

{193, 188, 0, 124, 52},

{46, 157, 214, 49, 246},

{1, 78, 167, 143, 204},

{98, 175, 159, 152, 248}

};

white_black(pix,5);

printf("----------- \n");

// C.

int UPC[10];

float price[10];

float Total=0;

for(int i = 0; i<10; ++i) {

printf("Enter UPC #%d:",i+1);

scanf("%d", &UPC[i]);

printf("Enter price #%d:",i+1);

scanf("%f", &price[i]);

Total = Total + price[i];

}

printf("Item ");

printf("Code ");

printf("Price \n");

for(int i=0; i<10; i++) {

printf("%d ",UPC[i]);

printf(" ");

printf("%.2f ",price[i]);

printf("\n");

}

printf("Total ");

printf(" ");

printf("%.2f ",Total);

}