Writing out the results to the console

Assignment Help C/C++ Programming
Reference no: EM13810120

This assignment consists of reading three files and writing out the results to the console. The three files can be found on Moodle: text.bin, bin_data.bin, and mixed.bin.

1) Reading text from a file

You are to open the file "text.bin" for reading. It contains a single line of text "Mary had a little lamb". You are to read this file, read the words, then write them to the console in reverse order. The output should read

"lamb little a had Mary".

Hint: Store the words in an array as you read them.

2) Reading binary data from a file

You are to open the file "bin_data.bin" for reading. It contains binary data written using the following data format:

struct binary {int a; float b; char letters[6];}

That is, there are three records in the array. Each record contains one int, one float, and 6 letters. You are to read the data and output it to the console. The output should look like (depending on formatting):

3 3.14 pi 2 1.414 sqrt 42 42.0 towel

Hint: Create a buffer of type binary and read the data into it. Then you can access it by bufferName.a, bufferName.b, bufferName.letters. Read and output one buffer full at a time until you reach the end of the file.

3) Reading and parsing mixed data

You are to open the file "mixed.bin" for reading. It contains ascii data that is a mixture of words and integers with spaces between each item. There are a total of four lines in the file, the fourth line contains "00". You should read a line of data, then break it into words and numbers, saving them in a string array and an integer array. You can ignore any spaces. When you are done reading the file, you should write out the saved data. The output should look like:

Horse House Elephant Dog Car Cat Mouse Rat Cow Pig Chicken

36 32 1 2 4 47 19 19 11 0

Hint: Read each line into a buffer. Then walk down the buffer one character at a time. If the character is a letter, then extract a word. If the character is a digit, then extract a number. If it is a space, then increment the index by one.

Reference no: EM13810120

Questions Cloud

Discuss elite democrats or popular democrats : Based on the published information on the websites, discuss whether individuals who associate with this group should be classified as elite democrats or popular democrats.
Discuss about peacekeeping : PEACEKEEPING
Project and evaluate the project success : In this activity, you synthesize the lessons you learned in completing your project and evaluate the project's success. Address the following questions in a separate document:
Write a response paper about essay dorian grays bad decision : Write a response paper about the essay "Dorian Gray's Bad Decisions".
Writing out the results to the console : This assignment consists of reading three files and writing out the results to the console. The three files can be found on Moodle: text.bin, bin_data.bin, and mixed.bin
Write response paper about the essay morals vs aestheticism : Write a response paper about the essay "Morals Vs. Aestheticism".
Assignment on mergers and acquisitions : Use the Internet to research a publicly traded company in the United States that has undergone a merger or acquisition within the last three (3) years. Take note of the circumstances surrounding the merger or acquisition.
Write a loop that will step through the array : Write a loop that will step through the array you defined in question 1, displaying the contents of each element that doesn't contain a NULL pointer
The role of the federal reserve : A specific piece of legislation relating to business regulation or taxation. The "party platform" of either the Republican Party or the Democratic Party or both

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Output the even numbers from 1 to 10 in ascending order

Output the even numbers from 1 to 10 in ascending order, then the odd numbers from 10 to 1 in descending order: 2 4 6 8 10 9 7 5 3 1. in C++

  Implement uniform random number generator

Implement Uniform Random Number generator and Generate 1000 Random number between 0 an 10000. Try to use insertion sort to sort them. Compare the running time of two versions of the insertion sort.

  Person class that includes fields for last name

Create a Person class that includes fields for last name, first name, and zip code. Include a default constructor that initializes last name, first name, and zip code to "X" if no arguments are supplied. Also include a display function. Write a ma..

  Write a program to calculate cars mileage

If you are using VisualStudio 2005, you should include time.h. The call to srand should use the time rather than a number entered by the user and looks like this: srand( static_cast(time( NULL )) ).

  Struct definition as the page table entry

Struct definition as the page table entry and the array that follows it as the page table. Implement the software simulation of least recently used algorithm in two C++ functions. Should RUN on UNIX.

  Value of x after the following code is executed

What will be the value of x after the following code is executed?int x = 20, y = 30;while (y

  Which of the following are valid case statements in a switch

What will following segment of code output? int x = 5; if (x != 2)      System,out.println( "This is true!"); else      System.out.println( "This is false!");      System.out.println("This is all folks!");

  Compare the running time of two versions of the insertion

implement Uniform Random Number generator and Generate 1000 Random number between 0 an 10000. Try to use insertion sort to sort them. Compare the running time of two versions of the insertion sort.

  Const int num_years

How do you get this program to get both player input and then display results(As described on bottom) #include  const int NUM_YEARS=15;//The number of years const int NAME_SIZE=32;//The max size of the player name string

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Reads numbers from input and prints them in reverse order

Write a C program that reads ten numbers from input and prints them in reverse order. We assume that the data consists of integers. The program should conform to the following format:

  Find maximum velocity and maximum acceleration

Find maximum velocity and maximum acceleration - Write a general function that can be used to find the maximum of any array. Call this function twice in order to find maximum velocity and maximum acceleration.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd