Assignment #12 Chapter 8 Write a C+ program that will ask the user for their nam
ID: 3567445 • Letter: A
Question
Assignment #12 Chapter 8 Write a C+ program that will ask the user for their name and street address. This information must written to a file name "original". Then the program will clear the screen and ask the user if they would like to update their street address. If the user decides to do so, you must read the data in from the file "original", display all of the current information and ask the user to input his name and new address. This information must then be written to a new file names "changed_info".Explanation / Answer
using namespace std;
#include<iostream>
#include<string>
#include<conio.h>
#include<stdio.h>
#include<fstream>
int main()
{
int i;
ofstream myfile,myfile2;
myfile.open("original.txt");
myfile << ("Name : ");
char choice;
char name[250],address[1000],address_new[1000];
system("cls");
cout<<"Enter your name : ";
gets(name);
for(i=0;name[i]!= '';i++)
myfile << name[i];
cout<<" Enter address : ";
gets(address);
myfile<<(" Address : ");
for(i=0;address[i]!= '';i++)
myfile << address[i];
myfile.close();
system("cls");
cout<<"Do you wish to update the address?(y/n): ";
cin>>choice;
if(choice=='y')
{
myfile2.open("changed_info.txt");
cout<<"Enter address: ";
cout<<" ";
gets(address_new);
myfile2<<"Name: ";
for(i=0;name[i]!= '';i++)
myfile2 << name[i];
myfile2<<" Address: ";
for(i=0;address_new[i]!= '';i++)
myfile2 << address_new[i];
myfile2.close();
system("pause");
return 0;
}
else
return 0;
system("pause");
return 0;
}