Answer to Question #286433 in C++ for yash gupta

Question #286433

Write a C++ program to copy a file into another file using following rules:



i) convert lowercase alphabets to uppercase alphabets and vice versa.



ii) copy other characters as it is.

1
Expert's answer
2022-01-11T02:16:26-0500
#include<conio.h>
#include <iostream>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include <cmath>
#include<dos.h>
#include <bits/stdc++.h> 
#include<vector>
using namespace std;


/*
	Write a C++ program to copy a file into another file using following rules:
	i) convert lowercase alphabets to uppercase alphabets and vice versa.
	ii) copy other characters as it is.
*/


main(void)
{
	ifstream infile,outfile; 
	char x,y;
	string Name1 = "H:\\Test_1.txt";
	string Name2 = "H:\\Test_2.txt";
	infile.open(Name1.c_str());
	outfile.open(Name2.c_str());
    if (!infile) 
	{
	    cout << "Unable to open file: "<<Name1;
        exit(1); // terminate with error
    }
	else
	{
		cout<<"\nContents of File_1.txt: ";
		while(infile >> x)
		{
			if(x>="a" && x <="z") {y = toupper(x); outfile<<y;} 
			if(x>="A" && x <="Z") {y = tolower(x); outfile<<y;} 
		}
		infile.close();
		outfile.close();
	}


	return(0);
}

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