Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This assignment uses functins, files, and strings. Apply basic C++ programing kn

ID: 3763783 • Letter: T

Question

This assignment uses functins, files, and strings. Apply basic C++ programing knowledge to develop a solution.

Develop a functional flowchart and then write a C++ program to solve the following problem.

1. Create a text file named number.txt and write your street number in the file. You will  be reading the name of the file from the keyboard as a string, using the string class. Your program will also read the street number from the keyboard. The process of the file creation (name of the file, mode for opening the file, and testing the open success is done in a user-defined function. The function communicates the status of file open to the calling function).

2. Create a text file named street.txt and write your street name in the file. You will  be reading the name of the file from the keyboard as a string, using the string class. Your program will also read your street name from the keyboard. The process of the file creation (name of the file, mode for opening the file and testing the open success is done in a user-defined function. The function communicates the status of file open to the calling function)

3. Create a text file named nstreet.txt and write your street number from the file number.txt, and your street name from the file street.txt. You will  be reading the name of the file from the keyboard as a string, using the string class. The process of the file creation (name of the file, mode for opening the file and testing the open success is done in a user-defined function. The function communicates the status of file open to the calling function)

4. At this time, each file will have one line of text in it.

5. Prepare the files for reading.

6. Display the results of the three files in the order shown below:

number.txt  your street number as written in the file

street.txt   your street name as written in the file

nstreet.txt  yourstreetnumber yourstreetname

Note that there is a single space between yourstreetnumber and yourstreetname when you display the contents of the file nstreet.txt.

You will use a user-defined function to display all the files at once or one at a time.

7. Close all files. You will use a user-defined function that closes each file separately or all at once.

8. Run the program again and use your choice of the filenames, and different street number and street name, different than what you used above and repeat the process.

The programs in the book and sample programs show you how to read file names as strings and how to convert the strings to the C string, if needed.
 

Notes: (please read very carefully)

1. Make sure your media is VIRUS FREE!

2. Comment your program.

3. Use meaningful prompts.

4. Provide a brief description of the problem being solved.

6. NO global declarations of VARIABLES allowed

7. Illegal inputs must be handled properly without terminating the program.

9. Use Microsoft Visual C++ .NET 2010 compiler using default compiler settings.

10. Use Microsoft Visio 2013 to develop the flowchart.

11. Adherence to the ANSI C++  required.

12. Do not use <stdio.h> and <conio.h>

13. Do not use any #define in the program

14. No goto statements allowed

15. Non-compliance with these notes will cost points

Explanation / Answer

#include //Always use meaningful names for types typedef unsigned char boolean; #define True 't' #define FALSE (!True) //this is a really neat trick for swapping values efficiently void swap(long* a,long *b) { *a=*a^*b;*b=*b^*a;*a=*a^*b; } //Here's a readability improvement #define until(condition) while(!(condition)) int main(int n, char*args[]){ double *d; int i; char input[5]; //should be long enough for most doubles. boolean sorted = FALSE; //In C, you need to specify the array size beforehand, so ask printf("Please enter the length of the array "); gets(input); //scan the input string and convert to a value sscanf(input,"%s",&input[0]); n=(long)atol(input); //allocate space, make sure you get the order of arguments right. d = calloc(sizeof(double),n); //Get and sort the array until (sorted) { for (i=0;i