Answer to Question #191279 in C++ for PRACHI PANWAR

Question #191279

write an interactive menu driven c++ program that creates a text file (say text1) and then display the file. create another text file (as text) by converting each line of the 'text1' file into a lowercase string. display the contents of 'text' file.


1
Expert's answer
2021-05-10T17:18:08-0400
#include<fstream>
#include<string>
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
void create_file()
{
    ofstream fout("text1.txt",ios::out);
    cout<<"\nFile created succesfully ";
    fout.close();
}
void Enter_data(char data[])
{
    ofstream fout("text1.txt",ios::out | ios::app);
    fout<<data;
    cout<<"\nData entered succesfully ";
    fout.close();
}
void convert_to_lower()
{
    string w,p,word,filename;
    ifstream fin("text1.txt",ios::in);
    fstream fout("text.txt",ios::in | ios::out | ios::app);
    while(getline(fin,w))
    {
        transform(w.begin(), w.end(), w.begin(), ::tolower);
        fout<<w;
    }
    fout.close();
    fstream file;
    filename = "text.txt";
    file.open(filename.c_str());
    while (file >> word)
    {
        cout << word << " ";
    }
    fin.close();
}
int main()
{
    int n;
    char data[300];
    cout<<"1. Create a text file ";
    cout<<"\n2. Enter data in file ";
    cout<<"\n3. Copy data to another file and convert to lowercase ";
    cin>>n;
    if(n==1)
    {
        create_file();
    }
    if(n==2)
    {
        gets(data);
        cin.getline(data,300);
        Enter_data(data);
    }
    if(n==3)
    {
        convert_to_lower();
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment