Can someone help me with this assignment? EXERCISE Submit answers for the following question. (4 pts) Assume the following declarations…

Can someone help me with this assignment?

EXERCISE

Don't use plagiarized sources. Get Your Custom Essay on
Can someone help me with this assignment? EXERCISE Submit answers for the following question. (4 pts) Assume the following declarations…
Get an essay WRITTEN FOR YOU, Plagiarism free, and by an EXPERT!
Order Essay

Submit answers for the following question.

(4 pts) Assume the following declarations:

char name[21];

char yourName[21];

char studentName[31];

Mark each of the following statement as valid or invalid. If a statement is valid, explain what it does. For an invalid statement, explain what’s wrong and correct it.

a. yourName[0] = ‘’;

b. yourName = studentName;

c. if (yourName == name) // if contain same words

std::cout << “Same word in ” << yourName << ” and ” << name;

d. for (int j=0; j < name.length; j++)

std::cout << name[j];

PROJECT: Image Processing

Write a program to simulate image processing (blur an image, see Unit 3_3_ch8_2dArray slides). An image file is simulated by a 2D array of ints. Shell code is provided in HW5_image_shell.cpp, which includes the following functions:

Process an image file (blur the image).

Print out blurred image on screen.

The screenshot below shows a sample image:

Remember, image blurring is done by calculating the weighted average of each pixel (each element of the 2D array). The weights are specified by a predefined 3 by 3 weight mask:

1 2 1

2 2 2

1 2 1

The center weight 2 (highlighted) is applied to a pixel itself and the other weights are applied to its 8 neighbors.

New value of a pixel = [ sum (weight for itself/neighbor × value of itself/neighbor) ] / sum of weights

We will use approach 1 for pixels with less than 8 neightbors:

Approach 1: pixels with fewer than 8 neighbors are not processed

Blurred result:

For example, new value for pixel[1][1] (in yellow rectangle) would be calculated based on itself and 8 neighbors.

new value for pixel[1][1]

= (1 * 10 + 2 * 100 + 1 * 10 +

2 * 10 + 2 * 300 + 2 * 10 +

1 * 100 + 2 * 10 + 1 * 100) / 14     // 14 is the sum of the weights: 1+2+1 + 2+2+2 + 1+2+1

= 1080 / 14

= 77.14… à 77 is kept as the result

You need to add code to ADD #1-2:

ADD #1: declaration of function blur. Be sure to add IN/OUT/INOUT comment to each parameter.

ADD #2: implementation of function blur

You’re not supposed to modify the given code otherwise (at least 10% penalty).

Submission: 2 files

In one word/pdf document:

Answers to exercise 1

Project: screenshot of program execution

One cpp file: HW5_image_YourLastName.cpp

Use the rubric below to check the completeness of your work before turning it in.

Rubric: CS225, HW5

Item Max

(Pts)

Received

(Pts)

Exercise (4 pts)
E1. C-string: for each one, ½ pts for answer, ½ pts for explanation 4
Project (14 pts)
function declaration for function blur with param type comments 1
implementation of function blur

Old value of each pixel is used when calculating new values

all pixels with 8 neighbors are processed correctly

approach 1: all pixels with fewer than 8 neighbors use old value

3

6

3

Your project compiles and runs. 1
Programming style (2 pts)

Consistent indentation: preferred 2 spaces for each level

Meaningful names for constants and variables; Proper comments in the program

0.5

1.5

Penalty
Modified given .cpp file in unspecified ways At least (-2)
Missing required screenshot(s) (-2)
Total: 20

// HW5_image_shell.cpp (shell code. ADD CODE #1 and #2)
// by Bin “Crystal” Peng, CS225
// image processing
// blur an image. print it on screen

#include <iostream>
#include <iomanip> // std::setw()

//———————————————-
// global declarations
//———————————————-

// max dimension of 2D array
const int MAX_ROW = 100;
const int MAX_COL = 100;

//———————————————-
// function declarations
//———————————————-

// blur an image
// Pre: pic filled with height x width numbers
// Post: pic is blurred using a 3 x 3 predefined weight mask

// ADD CODE #1: function declaration

// END ADD CODE #1

// print an image on screen
void printImage(const int pic[][MAX_COL]/*IN*/, int height/*IN*/, int width/*IN*/);
// Pre: pic filled with height x width numbers
// Post: image printed to screen. The height and width are printed first and then the image file data is printed

//———————————————-

int main()
{
// one image
int image[MAX_ROW][MAX_COL] = {
{ 10, 100, 10, 100, 10, 100 },
{ 10, 300, 10, 300, 10, 300 },
{ 100, 10, 100, 10, 100, 10 },
{ 300, 10, 300, 10, 300, 10 } };

int imgHeight = 4; // height of image
int imgWidth = 6; // width of image

// process the image
blur(image, imgHeight, imgWidth);
printImage(image, imgHeight, imgWidth);

return 0;
} // end main

//———————————————-
// Function Implementation
//———————————————-

// blur an image
// Pre: pic filled with height x width numbers
// Post: pic is blurred using a 3 x 3 predefined weight mask

// ADD CODE #2: implementation of function blur

// END ADD CODE #2

// print an image to output stream obj out
void printImage(const int pic[][MAX_COL]/*IN*/, int height/*IN*/, int width/*IN*/)
{
std::cout << height << ‘ ‘ << width << ‘n’;
for (int row = 0; row < height; row++)
{
for (int col = 0; col < width; col++)
{
std::cout << std::setw(4) << pic[row][col];
}
std::cout << ‘n’;
}

} // end printImage

Expert Answer

answers

a. yourName[0] = ‘’;

It is a valid statement. Assigns null character to the first(zeroeth) location of the array yourName.

b. yourName = studentName;

Invalid statement. Assignment to expression with array type will return an error as it’s not allowed.

You can use

strncpy(yourName, "studentName", 24); to assign values. It copies upto 24 characters from the string pointed to, by studentName to yourName.

Or you can use,

char yourName[21]=”studentName”; during the declaration itself.

c. if (yourName == name) // if contain same words

     std::cout << “Same word in ” << yourName << ” and ” << name;

Invalid statement as two arrays cant be matched in this way. You can use strcmp() function to check whether both arrays hold the same value.

if (strcmp(yourName, name)==0)
std::cout<<“Same word in “<<yourName<<” and “<<name;
else
std::cout<<“no”;

strcmp() returns 0 if both are identical. The standard library string.h should be imported to use this string fuction strcmp().

d. for (int j=0; j < name.length; j++)

     std::cout << name[j];

It would return an error as length is of non-class type ‘char[21]’. So if you want to print the elements of the array name you can use the function strlen() instead. The code goes like this,

for (int j=0; j < strlen(name); j++)

std::cout << name[j];

Hope it was helpful enough to answer your questions. Have a thumps up if it did. Thank You.

Top Grade Homework
Order NOW For a 10% Discount!
Pages (550 words)
Approximate price: -

Why Work with Us

Top Quality and Well-Researched Papers

We always make sure that writers follow all your instructions precisely. You can choose your academic level: high school, college/university or professional, and we will assign a writer who has a respective degree.

Professional and Experienced Academic Writers

We have a team of professional writers with experience in academic and business writing. Many are native speakers and able to perform any task for which you need help.

Free Unlimited Revisions

If you think we missed something, send your order for a free revision. You have 10 days to submit the order for review after you have received the final document. You can do this yourself after logging into your personal account or by contacting our support.

Prompt Delivery and 100% Money-Back-Guarantee

All papers are always delivered on time. In case we need more time to master your paper, we may contact you regarding the deadline extension. In case you cannot provide us with more time, a 100% refund is guaranteed.

Original & Confidential

We use several writing tools checks to ensure that all documents you receive are free from plagiarism. Our editors carefully review all quotations in the text. We also promise maximum confidentiality in all of our services.

24/7 Customer Support

Our support agents are available 24 hours a day 7 days a week and committed to providing you with the best customer experience. Get in touch whenever you need any assistance.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

Our Services

No need to work on your paper at night. Sleep tight, we will cover your back. We offer all kinds of writing services.

Essays

Essay Writing Service

No matter what kind of academic paper you need and how urgent you need it, you are welcome to choose your academic level and the type of your paper at an affordable price. We take care of all your paper needs and give a 24/7 customer care support system.

Admissions

Admission Essays & Business Writing Help

An admission essay is an essay or other written statement by a candidate, often a potential student enrolling in a college, university, or graduate school. You can be rest assurred that through our service we will write the best admission essay for you.

Reviews

Editing Support

Our academic writers and editors make the necessary changes to your paper so that it is polished. We also format your document by correctly quoting the sources and creating reference lists in the formats APA, Harvard, MLA, Chicago / Turabian.

Reviews

Revision Support

If you think your paper could be improved, you can request a review. In this case, your paper will be checked by the writer or assigned to an editor. You can use this option as many times as you see fit. This is free because we want you to be completely satisfied with the service offered.

× Contact Live Agents