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

use functions, strings, and write a C++ program to solve the following problem.

ID: 3763801 • Letter: U

Question

use functions, strings, and 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.

 

Notes: (please read very carefully)

3. Use meaningful prompts.

6. NO global declarations of VARIABLES allowed in any program that you develop in this course.

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 your flowchart.

11. Adherence to the ANSI C++  required.

12. Do not use <stdio.h> and <conio.h>  in this assignment and all other assignments.

13. Do not use any #define in your program until the time that is required for class declaration header files.

14. No goto statements allowed in any program that you develop in this course.

15. Non-compliance with these notes will cost you points.

16. No collaboration on this suv

Explanation / Answer

Source Code to Concatenate Two Strings without using strcat()

#include <iostream>

using namespace std;

int main()

{

    char s1[100], s2[100];

    int i, j;

    cout << "Enter first string: ";

    cin >> s1;

    cout << "Enter second string: ";

    cin >> s2;

    for(i=0; s1[i]!=''; ++i); /* i contains length of string s1. */

    for(j=0; s2[j]!=''; ++j, ++i)

    {

        s1[i]=s2[j];

    }

    s1[i]='';

    cout << "After concatenation: " << s1;

    return 0;

}

!!!!!!!!!!!!!!!!!!!!!!!!

!!!!!!!!!!!!!!!!!!!!!!!!!!!!

//****Again, it is for this reason that we prefer strncpy over strcpy, which is vulnerable to buffer overflows.

Example: