Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

4 Programming Question (40 points) 4.1 Instructions You need to write the code b

ID: 3871406 • Letter: 4

Question

4 Programming Question (40 points) 4.1 Instructions You need to write the code by yourself. Your implementation must use C/C++ and your code must run on the Linux machine general.asu.edu. Please refer to the programming guide (available under the Assignments folder on Blackboard) for using the general.asu.edu server, as well as compiling and running C/C++ code under Linux For this question, you need to provide a Makefile that compiles your program to an executable named a2 that runs on the Linux machine general.asu.edu. Our TA will write a script to compile and run all student submissions; therefore, executing the command make in the Code folder must produce the executable a2 also located in the Code folder 4.2 Requirements In this question, you will write a serial program that executes a sequence of commands that operate on individual files. Valid commands include: . Start Name, where Name is a character string of maximum length 20 alphabetic characters representing the name of the data file (Name.txt). The structure of Name.txt is an integer N indicating the total number of data entries contained in this file, followed by N additional lines of integers (the actual data entries). This command first reads N from the file Name.txt, dynamically allocates an array of integers of size N (if it has not already been allocated), and then reads the remaining N data entries into the array. The commands that follow until the End command are to be applied to the resulting data array The output of the Start command is Processing data from: Name.txt End Name, which indicates the end of the processing for the data in file Name.txt. The Start and End commands will always come in pairs with matching names. Any memory dynamically allocated for Name must be freed on an End command. The output of the End command is End of processing data from: Name.txt

Explanation / Answer

import java.awt.*;
02
import java.awt.event.*;
03
import java.awt.image.*;
04
import java.io.*;
05
import javax.imageio.*;
06
import javax.swing.*;
07
import java.util.Random;
08

09

10

11
public class BasicDisplay_2 extends Component{
12

13
private BufferedImage originalPic;
14
private Raster picRasterArray;
15
private DataBuffer picArray;
16

17
public void paint(Graphics g) {
18
g.drawImage(originalPic, 0, 0, null);
19
}
20

21
public BasicDisplay_2() {
22
try {
23

24
originalPic = ImageIO.read(new File("C://Users//Lily//Desktop//blue_balloons.jpg"));
25

26

27
picRasterArray = originalPic.getRaster();
28

29

30
System.out.println("************Image Properties***********");
31
System.out.println("Height in pixels: " + picRasterArray.getHeight());
32
System.out.println("Width in pixels: " + picRasterArray.getWidth());
33
System.out.println("Number of Color Bands: " + picRasterArray.getNumBands());
34

35
SampleModel st = picRasterArray.getSampleModel();
36
System.out.println("Image Sample Model: "+ st);
37

38

39
picArray = picRasterArray.getDataBuffer();
40
System.out.println("Total number of array elements in model: " +
41
picArray.getSize());
42

43

44
for(int i = 0; i<510; ++i){
45
st.setSample(i,300,0,0,picArray);
46
st.setSample(i,300,1,0,picArray);
47
st.setSample(i,300,2,0,picArray);
48
}
49

50
int []change = {255, 255, 255};
51

52

53
int randomRow, randomColumn;
54

55
Random randomGenerator = new Random(); //declartion of random generator object
56

57
for(int n=0; n<=80000; ++n){
58
randomColumn = randomGenerator.nextInt(510); //generate random column
59
randomRow = randomGenerator.nextInt(980); //generate random row
60
st.setPixel(randomColumn,randomRow,change,picArray); //change the pixel color
61
//at the row and column identified
62
}
63
} catch (IOException e) {
64
}
65
}
66

67
public Dimension getPreferredSize() {
68
if (originalPic == null) {
69
return new Dimension(800,700);
70
} else {
71
return new Dimension(originalPic.getWidth(null),
72
originalPic.getHeight(null));
73
}
74
}
75

76
public static void main(String[] args) {
77

78
JFrame f = new JFrame("Simple Image Processing");
79

80
f.addWindowListener(new WindowAdapter(){
81
public void windowClosing(WindowEvent e) {
82
System.exit(0);
83
}
84
});
85

86
f.add(new BasicDisplay_2());
87
f.pack();
88
f.setVisible(true);
89
}
90
}

#include <iostream>
using std::cout;
using std::cin;

int main()
{
int UserNumber;
char Grade;

cout << "Enter the grade you got on that test: ";
cin >> UserNumber;
cout << " ";

if (UserNumber > 89 && UserNumber < 101)
{
Grade = 'A';
}

else if (UserNumber > 79 && UserNumber < 91)
{
Grade = 'B';
}

else if (UserNumber > 69 && UserNumber < 81)
{
Grade = 'C';
}

else if (UserNumber > 59 && UserNumber < 71)
{
Grade = 'D';
}

else if (UserNumber > -1 && UserNumber < 61)
{
Grade = 'F';
}
else
{
Grade = 'Z';
}


switch (Grade)
{
case 'A':
cout << "Perfect! You got a: " << Grade;
break;
case 'B':
cout << "Could've been worse. You got a: " << Grade;
break;
case 'C':
cout << "It's okay I guess, you got a: " << Grade;
break;
case 'D':
cout << "Uggh.. You got a: " << Grade;
break;
case 'F':
cout << "Better luck next time! You got a: " << Grade;
break;
case 'Z':
cout << "Undefined value! Make sure it's a value from 0-100!";
break;


}
cout << " ";
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote