Task F
#include <iostream>
#include <cassert>
#include <cstdlib>
#include <fstream>
using namespace std;
const int MAX_H = 512;
const int MAX_W = 512;
// Reads a PGM file.
// Notice that: height and width are passed by reference!
void readImage(int image[MAX_H][MAX_W], int &height, int &width) {
char c;
int x;
ifstream instr;
instr.open("inImage.pgm");
// read the header P2
instr >> c;
assert(c == 'P');
instr >> c;
assert(c == '2');
// skip the comments (if any)
while ((instr>>ws).peek() == '#') {
instr.ignore(4096, '\n');
}
instr >> width;
instr >> height;
assert(width <= MAX_W);
assert(height <= MAX_H);
int max;
instr >> max;
assert(max == 255);
for (int row = 0; row < height; row++)
for (int col = 0; col < width; col++)
instr >> image[row][col];
instr.close();
return;
}
// Writes a PGM file
// Need to provide the array data and the image dimensions
void writeImage(int image[MAX_H][MAX_W], int height, int width) {
ofstream ostr;
ostr.open("outImage.pgm");
if (ostr.fail()) {
cout << "Unable to write file\n";
exit(1);
};
// print the header
ostr << "P2" << endl;
// width, height
ostr << width << ' ';
ostr << height << endl;
ostr << 255 << endl;
for (int row = 0; row < height; row++) {
for (int col = 0; col < width; col++) {
assert(image[row][col] < 256);
assert(image[row][col] >= 0);
ostr << image[row][col] << ' ';
ostr << endl;
}
}
ostr.close();
return;
}
int main() {
int img[MAX_H][MAX_W];
int h, w;
int avg = 0;
readImage(img, h, w); // read it from the file "inImage.pgm"
// h and w were passed by reference and
// now contain the dimensions of the picture
// and the 2-dimesional array img contains the image data
// Now we can manipulate the image the way we like
// for example we copy its contents into a new array
int out[MAX_H][MAX_W];
for(int row = 0; row < h; row++) {
for(int col = 0; col < w; col ++) {
avg = (out[row][col] + out[row][col + 1] + out[row + 1][col] + out[row + 1][col + 1])/4; // find ave
out[row][col] = out[row][col + 1] = out[row + 1][col] = out[row + 1][col + 1] = avg;
col += 2; // skip a col
row += 2; // skip a row
}
}
// and save this new image to file "outImage.pgm"
writeImage(out, h, w);
}
O https//maryash.github.io/135/labs/lab 08 html Since the program should work for all input image...
NB: All C programs should be compiled using C Compiler application. The code should be shown on the document. A screen shot of the running program given as output on the assignment. a). Describe the types of arrays and operations that can be performed of them. [10] b). Write a program to print the multiplication table from 1*1 to 12*10. [10] Example MULTIPLICATION TABLE 1 2 3 4 5 6 7 8 9 10 2 4 6 8 10 12...
HTML Text Query All La Edit Links X & fx 844 STION C2 A B C D E F s the date 1 Highway ataset ab 2 uct a 5% F 3 ANOVA, 5 6 4 Gas Conven 952 1298 844 996 1195 921 839 1174 880 1088 1113 706 1024 953 602 1280 614 7 Τ Τ + 8 9 10 11 Mashups 12 13 14 15 16 17 18 19 Path: P 20 21 22 23 24 25...
Please show how you did this in excel. :13-19 Every home football game for the past eight years at Eastern State University has been sold out. The revenues from ticket sales are significant, but the sale of food, beverages, and souvenirs has contrib- uted greatly to the overall profitability of the football program. One particular souvenir is the football pro- gram for each game. The number of programs sold at each game is described by the following probabil- ity distribution:...
Programming Exercise 8.3 | Instructions Write a GUI-based program that allows the user to convert temperature values between degrees Fahrenheit and degrees Celsius. The interface should have labeled entry fields for these two values. breezypythongui.py temperatureconvert... + 1 2 File: temperatureconverter.py 3 Project 8.3 4 Temperature conversion between Fahrenheit and Celsius. 5 Illustrates the use of numeric data fields. 6 • These components should be arranged in a grid where the labels occupy the first row and the corresponding fields...
this is c code. please answer all questions on a piece of paper and show work. i need to prepare as i have a midterm i will have to be completing on paper 1) Bit Operators: This C program compiles and runs. What is its output? 1) #include <stdio.h> 2) void main (void) 3) unsigned char x =60; 4) 5) 6) 7) 8 ) 9) 10) 11) 12) 13) unsigned char a = x < 1; unsigned char b unsigned...
I posted this question earlier but realized that the code was not easy to test since it was just screenshots and not text so I am reposting it: I'm very new at working with file streams, and I'm having trouble with a HW assignment I have to work on. For the assignment I have to read an input file named "MagicSquaresIn.txt" (included at the bottom) and I have to check whether they are normal, associative, and panmagic. To check that...
Instructions CheckZips.cs + >_ Terminal Write a program named CheckZips that is used by a package delivery service to check delivery areas. 1 using static System.Console; 2 class CheckZips 3 { 4 static void Main() 5 { 6 string[] zips = {"12789", "54012", "54481", "54982", "60007", "60103", "60187", "60188", "71244", "90210"}; CheckZips.cs(10,8): error CS002 9: Cannot implicitly convert ty pe 'string' to 'string[]' CheckZips.cs(18,5): error CS001 9: Operator '==' cannot be appl ied to operands of type 'string []' and...
please show all work and explain here is the data and explanation of 12.4 here is appendix D 12.12. * In Problem 12.4, find the value of x2. If the dice really are true, what is the probability of getting a value of X2this large or larger? Explain whether the evidence suggests the dice are loaded. (See Appendix D for the necessary probabili- ties.) 12.4.I throw three dice together a total of 400 times, record the number of sixes in...
Write a Python program (question2.py) that reads from a file called “input.txt” numbers in [1,39] separated in by commas. The numbers are in [1-99]. The program will then convert each number to a possible Roman Numeral equivalent, and print it on the screen. Remember, I is 1, V is 5, X is 10 For example, if the input is: 23, 11 the output is: XXIII, XI. ROMAN NUMERALS CHART 1 TO 100 69 LXIX 11 2 11 3 III 4...
Complete function long_list_printer.print_list(). When it's finished, it should be able to print this list, a = [ [93, 80, 99, 72, 86, 84, 85, 41, 69, 31], [15, 37, 58, 59, 98, 40, 63, 84, 87, 15], [48, 50, 43, 68, 69, 43, 46, 83, 11, 50], [52, 49, 87, 77, 39, 21, 84, 13, 27, 82], [64, 49, 12, 42, 24, 54, 43, 69, 62, 44], [54, 90, 67, 43, 72, 17, 22, 83, 28, 68], [18, 12, 10,...