Question: C++ Write and test a function void modifyChar(char c) that uses direct binary access to find and change the characters stored in the file containing
"C++" Write and test a function void modifyChar(char c) that uses direct binary access to find and change the characters stored in the file containing the diamonds to display from question 60. The characters should all be changed to the char c input into the function.
Question 60 :
Can you modify your code from question 16, using sequential file access, to write to a file a string that contains the diamond to display? For each time the code is run the diamond string will be added to the file. Create a menu option to display the contents of the file. E.g. for one diamond of size 3 and character * the output would be: * *** ***** *** *
Question 15 and 16
15. Can you modify your code from question 14 to display a diamond? E.g. for size 3 the output would be: * *** ***** *** * 16*.Write and test a function void diamond(int n, char c) to output a similar diamond to that in question 15, but passing a character to print out as a parameter instead of using an *.
and this answer 16:
#include
using namespace std;
void diamond(int n, char c)
{
for (int raw = 1; raw <= n; raw++)
{
for (int space = 0; space < n - raw; space++)
{
cout << " ";
}
for (int star = 0; star < 2 * raw - 1; star++)
{
cout << c;
}
cout << endl;
}
for (int raw = 1; raw < n; raw++)
{
for (int space = 0; space < raw; space++)
{
cout << " ";
}
for (int star = n * 2 - 2; star > 2 * raw - 1; star--)
{
cout << c;
}
cout << endl;
}
}
int main()
{
int traws = 3;
char star = '*';
diamond(traws, star);
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
