Write a C++ program that reads the contents of a file called in.dat. Your progra
ID: 3562253 • Letter: W
Question
Write a C++ program that reads the contents of a file called in.dat. Your program should create a new file out.dat according to the following rules: If you read a lowercase letter, then write it to the new file. If you read an uppercase letter, convert it to the lowercase and then write the lowercase letter to the file. If you read a newline character, then write two newline characters to the file. If you read a space character, then write the space character to the file. If you read a tab character, then write a space character to the file. Keep a count of all other characters that you read, but do not write them to the file. Report the number of characters you did not write to the file.
File in.dat
Introduction
Repetition statements are used in C++ programming to change the flow of control.
Repetition statements allow a programmer to direct the computer to execute a statement
or group of statements multiple times. Repetition statements are also called loops.
In this chapter you will review the while loop, the for loop, and the do while loop.
These are the three types of repetition statements in the C++ programming language.
You will also review additional I/O statements that are often used to control loops
as well as additional C++ operators that are often used in repetition statements
Explanation / Answer
#include <iostream>
#include<stdio.h>
using namespace std;
int main()
{
char c = 'P';
int count=0;
FILE *fileR,*fileW;
fileR=fopen("in.dat.txt" , "r");
fileW=fopen("out.dat.txt" , "w");
do
{
c=fgetc(fileR);
if ( c>='A' && c<='Z' )
{
fputc( c+32 , fileW );
}
else if( c>=97 && c<='z' )
{
fputc(c,fileW);
}
else if( c == ' ' )
{
fputc( c , fileW );
fputc( c , fileW ) ;
}
else if( c == ' ' )
{
c = ' ';
fputc( c , fileW );
}
else if( c == ' ' )
{
fputc( c , fileW );
}
else
{
count++;
}
}while( c != EOF);
cout<<"No of Character not written to file : "<<count;
}
OUTPUT FILE IS:
introduction
repetition statements are used in c programming to change the flow of control
repetition statements allow a programmer to direct the computer to execute a statement
or group of statements multiple times repetition statements are also called loops
in this chapter you will review the while loop the for loop and the do while loop
these are the three types of repetition statements in the c programming language
you will also review additional io statements that are often used to control loops
as well as additional c operators that are often used in repetition statements
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.