Ask Java Expert


Home >> Java

You will write a program that reads from one file, interprets what it reads and writes to a second fine.

There is an example input file in Moodle: infile.dat. You will need to copy those files onto your computer in the same folder that contains the main.cpp program for this project.

The program should then do the following things:

1) Open infile.dat for reading.
2) Open outfile.dat for writing.
3) Read the information on infile.dat, one line at a time, until the file is at EOF.
4) Interpret the information read and write the appropriate output on outfile.dat.
5) Close both files.

In Moodle there are example programs that open a file and read from it, write to it, or append to it. You should use these to give you an idea of how to do the file I/O portion of this exercise.

Each record (line) of infile.dat will have the following format: code char value1 value2(optional) The code will be from the following set of characters: D, R, S, T, E.

The char will be a single character and indicate what character you should use to create your output figure.

The values will be the size of the output figure. For D, S, and T, there will be only one value. For R, there will be two. E will have no additional values on its line.

End

If the code is an E, you are to end the program. Diamond

If the code is a D, you are to create a diamond of the char. Diamonds should always have an odd number for their dimension. For example, with the line

D ! 3

You should generate a diamond that looks like

  !
! ! !
  !

For the line D *5

You should generate a diamond that looks like

    *
  ***
*****
  ***
   *

Square

If the code is an S, you are to create a square of the char. For example, with the line S!3 You should generate a square that looks like

! ! !
! ! !
! ! !

For the line S@5

You should generate a square that looks like

@@@@@
@@@@@
@@@@@
@@@@@
@@@@@

Triangle

If the code is a T, you are to create a triangle of the char. For example, with the line T=3

You should generate a triangle that looks like

  =
 ==
===

For the line T^ 5

You should generate a triangle that looks like
    ^
   ^^
  ^^^
 ^^^^
^^^^^

Rectangle

If the code is an R, you are to create a rectangle of the char. Rectangles, have two values, rows and columns. For example, with the line
R a 2 4

You should generate a rectangle that looks like aaaa

aaaa

For the line R &6 3

You should generate a rectangle that looks like

&&&&&&

&&&&&&

&&&&&&

Notes to keep in mind:

• Before starting, think about what information you'll need to keep track of during

• The program will use a reading loop, some way to determine what code was entered, and a function to draw each shape. The function will need to have as parameters the character to use to draw the shape, the dimension(s) of the shape, and the ouput file to write it on.

• You should check for an improper file. That is, if you get an EOF when trying to read something, you should exit the program with an error message.

Example Input File T&4

S@6 Tx5
R *5 7 D-7 D +5
R =43 E

Evaluation

Before you submit your work, take a look at the evaluation criteria and make sure that your program meets them.

Attachment:- Main_.cpp

Java, Programming

  • Category:- Java
  • Reference No.:- M91560300
  • Price:- $50

Priced at Now at $50, Verified Solution

Have any Question?


Related Questions in Java

Chatbotscreate a small networked chat application that is

Chatbots Create a small, networked chat application that is populated by bots. Introduction On an old server park, filled with applications from the early days of the internet, a few servers still run one of the earliest ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Assignment game prototypeoverviewfor this assessment task

Assignment: Game Prototype Overview For this assessment task you are expected to construct a prototype level/area as a "proof of concept" for the game that you have designed in Assignment 1. The prototype should function ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

In relation to javaa what is constructor the purpose of

(In relation to Java) A. What is constructor? the purpose of default constructor? B. How do you get a copy of the object but not the reference of the object? C. What are static variables and instance variables? D. Compar ...

Project descriptionwrite a java program to traverse a

Project Description: Write a java program to traverse a directory structure (DirWalker.java) of csv files that contain csv files with customer info. A simple sample in provided in with the sample code but you MUST will r ...

Fundamentals of operating systems and java

Fundamentals of Operating Systems and Java Programming Purpose of the assessment (with ULO Mapping) This assignment assesses the following Unit Learning Outcomes; students should be able to demonstrate their achievements ...

Assessment -java program using array of Assessment -JAVA Program using array of objects

Assessment -JAVA Program using array of objects Objectives This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details For this assignment, you are required to develop a Windowed G ...

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

Retail price calculatorwrite a java program that asks the

Retail Price Calculator Write a JAVA program that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example: (If an item's wholesale cost is 5. ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As