Question
algorithm are all given. Plz show complete code
Project 1.2: You are to write a very simple method, it is called, PrettyPrint. PrettyPrint method is an independent program, its sole purpose is for us to visualized a given image. PrettyPrint will be used in many occasions, for grey-scale and binary images. / You should be able to write this in less than 2 hours Language: C++ Due date: C++ Soft copy: 2/07/2018 Wednesday before Midnight Due date: C++ Hard copy: 2/08/2018 Thursday in class I Input (argv1) a txt file representing an image (grey scale or binary) II. Output: the name of the output should have the tollowing format: fileName PP where fileName is the name of input file For example: a grey-scale image below on the left, the pretty print on the right 4 6 1 12 0 3 4 0 2 9 560207 1 10 99 4 5 6999 4 6 01 3 42 9 à 5 6 2 7 11 1 9 9 4569 9 III. Data structure: - numRows (int) - numCols (int) - minVal (int)
media%2Fae4%2Fae4ac5f5-e9d2-44c9-b135-79
---
-------


media%2Fb95%2Fb95764ae-8165-4c0a-add6-59

media%2F172%2F17266d63-978b-4836-955f-9c
media%2F77e%2F77e13637-334c-48fc-95eb-04
------


media%2F88b%2F88bb4e64-fdca-495a-8c32-d7
media%2F91a%2F91a3cc94-a16d-4322-9046-a7
media%2F400%2F400c8d29-b7ac-41d5-8297-9a
0 0
Add a comment Improve this question Transcribed image text
Answer #1

I've provided the solution for:

Problem 1.1

Please create a file "input.txt" containing the input before running the program

import java.io.*;
import java.util.*;

public class HistogramPixel
{
  
int numRows;

int numCols;
  
int maxVal;

int minVal;

int hist[];
Scanner scanner;
  
HistogramPixel(String path) throws IOException //Constructor
{
//Read the data and initialize
scanner =new Scanner(new File(path));
numRows=scanner.nextInt();

numCols=scanner.nextInt();
  
minVal=scanner.nextInt();

maxVal=scanner.nextInt();

hist=new int[maxVal+1];  
}
  

public void computeHistogram () throws FileNotFoundException
{
int pixel;

//Read the rest of the file
while(scanner.hasNextInt())
{
pixel=scanner.nextInt();
hist[pixel]++;
}

//Write to a new output file

PrintWriter writer=new PrintWriter("output.txt");
writer.println(numRows+" "+numCols+" "+minVal+" "+maxVal);
for( int i=0;i <=maxVal;i++)
writer.println(i+" "+hist[i]);
writer.close();
}

public static void main(String args[])
{
  
try{
  
HistogramPixel obj=new HistogramPixel(args[0]); //arg[0] is the file name
  
obj.computeHistogram();
}

catch(Exception e)
{
System.out.println("FILE I/O EXCEPTION"+e);
}
}

}

Add a comment
Know the answer?
Add Answer to:
algorithm are all given. Plz show complete code --- ------- ------ Project 1.2: You are to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Need this in C The starter code is long, if you know how to do it...

    Need this in C The starter code is long, if you know how to do it in other way please do. Do the best you can please. Here's the starter code: // ----------------------------------------------------------------------- // monsterdb.c // ----------------------------------------------------------------------- #include #include #include // ----------------------------------------------------------------------- // Some defines #define NAME_MAX 64 #define BUFFER_MAX 256 // ----------------------------------------------------------------------- // Structs typedef struct { char name[NAME_MAX]; int hp; int attackPower; int armor; } Character; typedef struct { int size; Character *list; } CharacterContainer; // ----------------------------------------------------------------------- //...

  • All those points need to be in the code Project 3 Iterative Linear Search, Recursive Binary...

    All those points need to be in the code Project 3 Iterative Linear Search, Recursive Binary Search, and Recursive Selection Sort Class River describes river's name and its length in miles. It provides accessor methods (getters) for both variables, toString() method that returns String representation of the river, and method isLong() that returns true if river is above 30 miles long and returns false otherwise. Class CTRivers describes collection of CT rivers. It has no data, and it provides the...

  • Extend the code from Lab6.A template is given to you with CircleHeader.h, Circle.cpp and CircleMain.cpp Use...

    Extend the code from Lab6.A template is given to you with CircleHeader.h, Circle.cpp and CircleMain.cpp Use the same Circle UML as below and make extensions as marked and as needed. Given below is a UML for the Painting Class. You will need to write PaintingHeader.h and Painting.cpp. The Painting Class UML contains a very basic skeleton. You will need to flesh out this UML and add more instance variables and methods as needed. You do NOT need to write a...

  • (C++ programming) Need help with homework. Write a program that can be used to gather statistical...

    (C++ programming) Need help with homework. Write a program that can be used to gather statistical data about the number of hours per week college students play video games. The program should perform the following steps: 1). Read data from the input file into a dynamically allocated array. The first number in the input file, n, represents the number of students that were surveyed. First read this number then use it to dynamically allocate an array of n integers. On...

  • First create the two text file given below. Then complete the main that is given. There...

    First create the two text file given below. Then complete the main that is given. There are comments to help you. An output is also given You can assume that the file has numbers in it Create this text file: data.txt (remember blank line at end) Mickey 90 Minnie 85 Goofy 70 Pluto 75 Daisy 63 Donald 80 Create this text file: data0.txt (remember blank line at end) PeterPan 18 Wendy 32 Michael 28 John 21 Nana 12 Main #include...

  • Help with programming in C++ Phase 1 is complete, please help with phase 2. Thank you....

    Help with programming in C++ Phase 1 is complete, please help with phase 2. Thank you. Phase 1 You must design 3 algorithms, and provide both a flow chart and pseudo code for the algorithms.    Algorithm descriptions: Given an integer parameter named current_number and two constant global variables: const int MIN_NUMBER = 1; const int MAX_NUMBER = 8; Create an algorithm named forward, that will advance ONE value through a sequence of numbers 1, 2, 3 ... MAX_NUMBER. In...

  • Using the diagram below and the starter code, write Document Processor that will read a file...

    Using the diagram below and the starter code, write Document Processor that will read a file and let the user determine how many words of a certain length there are and get a count of all of the word lengths in the file. Your program should do the following: The constructor should accept the filename to read (word.txt) and then fill the words ArrayList up with the words from the file. The countWords method should accept an integer that represents...

  • This is the contents of Lab11.java import java.util.Scanner; import java.io.*; public class Lab11 { public static...

    This is the contents of Lab11.java import java.util.Scanner; import java.io.*; public class Lab11 { public static void main(String args[]) throws IOException { Scanner inFile = new Scanner(new File(args[0])); Scanner keyboard = new Scanner(System.in);    TwoDArray array = new TwoDArray(inFile); inFile.close(); int numRows = array.getNumRows(); int numCols = array.getNumCols(); int choice;    do { System.out.println(); System.out.println("\t1. Find the number of rows in the 2D array"); System.out.println("\t2. Find the number of columns in the 2D array"); System.out.println("\t3. Find the sum of elements...

  • I have 2 issues with the C++ code below. The biggest concern is that the wrong...

    I have 2 issues with the C++ code below. The biggest concern is that the wrong file name input does not give out the "file cannot be opened!!" message that it is coded to do. What am I missing for this to happen correctly? The second is that the range outputs are right except the last one is bigger than the rest so it will not output 175-200, it outputs 175-199. What can be done about it? #include <iostream> #include...

  • Kindly follow the instructions provided carefully. C programming   Project 6, Program Design One way to encrypt...

    Kindly follow the instructions provided carefully. C programming   Project 6, Program Design One way to encrypt a message is to use a date’s 6 digits to shift the letters. For example, if a date is picked as December 18, 1946, then the 6 digits are 121846. Assume the dates are in the 20th century. To encrypt a message, you will shift each letter of the message by the number of spaces indicated by the corresponding digit. For example, to encrypt...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT