Question

Using PUTTY We will create functions.h and functions.cpp to separate the read and write function from...

Using PUTTY

We will create functions.h and functions.cpp to separate the read and write function from main function. Use the following steps:o Create a directory called lab07o Upload the yourlastnameFirstnameLab06a.cpp from your computer to the csegrid.

Create a functions.h file with the following:

#ifndef _READWRITE

#define _READWRITE

void readWrite( );

#endif

Create a functions.cpp#include functions.hImplement readWrite() with the code in case 1 of the main.cpp.

Modify yourlastnameFirstnameLab06a.cpp

#include functions.h

Call readWrite for case 1 (instead of the case1 code)

Compile your code with the command:g++ -lab06a main.cpp functions.cpp

#ifndef _READWRITE #define _READWRITE void readWrite( );

#endif

Create a functions.cpp #include functions.h Implement readWrite() Modify main.cpp #include functions.h Call readWrite

Compile your code with the command: g++ -o lab06a yourlastnameFirstnameLab06a.cppfunctions.cpp

Please let me know if you need any other information.

Thank you

Homework Answers

Answer #1

Here is the solution to your question. I tried my best to solve your doubt, however, if you find it is not as good as expected by you. Please do write your further doubts regarding this question in the comment section, I will try to resolve your doubts regarding the submitted solution as soon as possible.

Please give proper indentation as shown in the screenshot

If you think, the solution provided by me is helpful to you please do an upvote.

As you have not provided anything for the function readWrite(), I am solving your problem by defining a dummy function that simply reads and writes files.

main.cpp

#include <iostream>

#include "functions.h"

int main()

{

readWrite();

return 0;

}

functions.h

#ifndef _READWRITE

#define _READWRITE

void readWrite( );

#endif

functions.cpp

#include <iostream>

#include <fstream>

#include "functions.h"

using namespace std;

void readWrite()

{

// Writing

// Create and open a text file

ofstream MyFile("filename.txt");

// Write to the file

MyFile << "data to be written\n";

// Close the file

MyFile.close();

// Reading

// Create a text string, which is used to output the text file

string myText;

// Read from the text file

ifstream MyReadFile("filename.txt");

// Use a while loop together with the getline() function to read the file line by line

while (getline (MyReadFile, myText))

{

// Output the text from the file

cout << myText<<endl;

}

// Close the file

MyReadFile.close();

}



filename.txt
Output
Know the answer?
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
Similar Questions
C++ See the provided specification files. Complete the implementation for each as a separate file. void...
C++ See the provided specification files. Complete the implementation for each as a separate file. void seen(std::string); If there is already a Word object in the Words list, then the number of occurrences for this word is incremented. If there is no Word object for this word already, create a new word object with occurrence =1, and insert this object into the list of Word objects. std::string getNextWord(); Returns the next word of the list and sets the currentItem pointer...
please use linux/unix command terminal to complete, step 1 1-create a new directory named by inlab4...
please use linux/unix command terminal to complete, step 1 1-create a new directory named by inlab4 enter directory inlab4 create a new file named by reverse.c with the following contents and then close the file: /*reverse.c */ #include <stdio.h> reverse(char *before, char *after); main() { char str[100]; /*Buffer to hold reversed string */ reverse("cat", str); /*Reverse the string "cat" */ printf("reverse(\"cat\")=%s\n", str); /*Display result */ reverse("noon", str); /*Reverse the string "noon" */ printf("reverse(\"noon\")=%s\n", str); /*Display result */ } reverse(char *before,...
can you please do this lab? use lunix or C program its a continuation of a...
can you please do this lab? use lunix or C program its a continuation of a previous lab. the previous lab: Unix lab 4: compile and link multiple c or c++ files Please do the following tasks step by step: create a new directory named by inlab4 enter directory inlab4 create a new file named by reverse.c with the following contents and then close the file: /*reverse.c */ #include <stdio.h> reverse(char *before, char *after); main() {       char str[100];    /*Buffer...
Menu.cpp isn't working. C++  utilize inheritance to create a banking app. The architecture of the app is...
Menu.cpp isn't working. C++  utilize inheritance to create a banking app. The architecture of the app is up to you as long as you implement some form of inheritance. Below is my code however the credit and the actual menu isn't working. Can i get some help on getting the menu to work properly. // BankAccount.h #ifndef ACCOUNT_H #define ACCOUNT_H #include <string> #include <iostream> using namespace std; class BankAccount { protected : int noOfWithdrawls; private: // Declaring variables    float balance;...
Implement and demonstrate a disk-based buffer pool class based on the LRU buffer pool replacement strategy....
Implement and demonstrate a disk-based buffer pool class based on the LRU buffer pool replacement strategy. Disk blocks are numbered consecutively from the beginning of the file with the first block numbered as 0. Assume that blocks are 4096 bytes in size. Use the supplied C++ files to implement your LRU Buffer Pool based on the instructions below. • Implement a BufferBlock class using the supplied BufferBlockADT.h o Your Buffer Block must inherit BufferBlockADT or you will not get credit...
Write a function to check if a machine uses little endian or big endian notation. write...
Write a function to check if a machine uses little endian or big endian notation. write the function checkEndianess(), complete the main function implementation to print the value returned by the function and print if the machine is “Little Endian” or “Big Endian”, compile and run the program. The function checkEndianess() should return the following values: • 0 if the architecture is "Little Endian" • 1 if the architecture is "Big Endian". #include int main() { int check; // Variable:...
Consider the C program (twoupdate) to demonstrate race condition. In this assignment, we will implement Peterson's...
Consider the C program (twoupdate) to demonstrate race condition. In this assignment, we will implement Peterson's algorithm to ensure mutual exclusion in the respective critical sections of the two processes, and thereby eliminate the race condition. In order to implement Peterson's Algorithm, the two processes should share a boolean array calledflagwith two components and an integer variable called turn, all initialized suitably. We will create and access these shared variables using UNIX system calls relating to shared memory – shmget,...
Using the C programming language implement Heapsort in the manner described in class. Here is some...
Using the C programming language implement Heapsort in the manner described in class. Here is some example code to use as a guideline. Remember, you need only implement the sort algorithm, both the comparison and main functions have been provided. /* * * after splitting this file into the five source files: * * srt.h, main.c, srtbubb.c, srtinsr.c, srtmerg.c * * compile using the command: * * gcc -std=c99 -DRAND -DPRNT -DTYPE=(float | double) -D(BUBB | HEAP | INSR |...
C Program Write a program to count the frequency of each alphabet letter (A-Z a-z, total...
C Program Write a program to count the frequency of each alphabet letter (A-Z a-z, total 52 case sensitive) and five special characters (‘.’, ‘,’, ‘:’, ‘;’ and ‘!’) in all the .txt files under a given directory. The program should include a header count.h, alphabetcount.c to count the frequency of alphabet letters; and specialcharcount.c to count the frequency of special characters. Please only add code to where it says //ADDCODEHERE and keep function names the same. I have also...
C++ Goals:Practicing arrays Create a program that will read whole numbers from a file called Labs4-7Mu.dat...
C++ Goals:Practicing arrays Create a program that will read whole numbers from a file called Labs4-7Mu.dat (posted on Canvas)and store it into an array. The number of values in the file is less than 300 and all the values are whole numbers. The actual number of values stored in the file should be determined. Your program should then prompt the user to enter another whole number between 2 and 20 (you may assume the user enters a valid value) and...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT