Question: Do the following in visual studio code: Problem 1 Deliverable: problem 1 . cpp Purpose: Create a program that will accept characters input from the

Do the following in visual studio code:
Problem 1
Deliverable: problem1.cpp
Purpose: Create a program that will accept characters input from the standard input device
(using cin). The program should stop accepting input when a period, question mark, or
exclamation point is input (.? or !). The program will output the number of alphabetic characters
(a-z A-z) and the number of digits (0-9) that were input in the form Input sentence contains
number alphabetic character/characters and number digit/digits. Note: the words character and
digit should be singular or plural as appropriate.
Specifications:
- Do not prompt for the program input.
- Assume the input sentence will be from the standard input device (using cin).
- Produce all output to the standard output device (using cout).
Sample input output pairs:
Input: Count characters in this sentence.
Output: Input sentence contains 29 alphabetic characters and 0 digits.
Input: Hey, do you count 12 letters?
Output: Input sentence contains 20 alphabetic characters and 2 digits.
Input: 1 more win!
Output: Input sentence contains 7 alphabetic characters and 1 digit.
Initial Testing:
A makefile, checkit.cpp source file, and sample input and output files have been provided to run initial tests on your program. To run the tests provided, create a directory containing only your problem1.cpp file and the files extracted from the attached problem1tests.zip.
makefile for problem 1:
#
# $@ target
# $< first prerequisite
# $^ all prerequisites
flags =-std=c++17-Wall -I .
problem1.o : problem1.cpp
g++ $(flags)-c $<
problem1 : problem1.o
g++ $(flags) $<-o $@
checkit : checkit.cpp
g++ $(flags) $^-o $@
problem1test1 : checkit problem1 problem1-sample-input-1.txt
./problem1< problem1-sample-input-1.txt > problem1-student-output-1.txt
./checkit 0
problem1test2 : checkit problem1 problem1-sample-input-2.txt
./problem1< problem1-sample-input-2.txt > problem1-student-output-2.txt
./checkit 1
problem1test3 : checkit problem1 problem1-sample-input-3.txt
./problem1< problem1-sample-input-3.txt > problem1-student-output-3.txt
./checkit 2
clean :
rm *.o checkit problem1 problem1-student-output-*.txt
Checkit.cpp:
#include
using std::ifstream;
#include
using std::cout;
using std::endl;
using std::cin;
#include
using std::string;
#include
int main(int argc, char *argv[]){
// executable must be called with a test number 0-2
if ( argc !=2|| argv[1][0]<'0'|| argv[1][0]>'4'){
cout << "Invalid test" << endl;
return 1;
}
// convert the character to an integer
int which = argv[1][0]-'0';
string correct[3]={ "problem1-expected-output-1.txt",
"problem1-expected-output-2.txt",
"problem1-expected-output-3.txt"};
string student[3]={ "problem1-student-output-1.txt",
"problem1-student-output-2.txt",
"problem1-student-output-3.txt"};
ifstream correctfile(correct[which]);
ifstream studentfile(student[which]);
bool match = true;
char correctchar, stuchar;
int i =0;
cout << "Your output:" << endl;
correctchar = correctfile.get();
stuchar = studentfile.get();
while ( correctfile.good() && studentfile.good() && match ){
match = correctchar == stuchar;
cout << stuchar;
if (!match )
cout <<"<- this character "
<<(isspace(stuchar)?"(a white-space character)" : "")
<< "should be "<< correctchar
<<(correctchar ==''?"(a space)" :
(correctchar =='\t'?"(a tab)" :
(correctchar =='
'?"(a newline)" : "")))<< endl;
++i;
correctchar = correctfile.get();
stuchar = studentfile.get();
}
cout <<"
";
if (!match )
cout << "output error at character "<< i
<<"
Open "<< student[which]<<" to view your full output and "
<< "compare it to the expected ouput in "<< correct[which]<< endl;
else if (!correctfile.eof())
cout << "student file ended too soon (make sure your last output statement "
<< "ends with endl)
Open "<< student[which]<<" to view your "
<< "full output and compare it to the expected ouput in "
<< correct[which]<< endl;
else if (!studentfile.eof())
cout << "extra output in student file"
<<"
Open "<< student[which]<<"

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!