Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 1 Deliverable: problem1.cc Test all of your code on a Linux lab computer. All source files submitted must compile and run on a Linux

Problem 1

Deliverable: problem1.cc

Test all of your code on a Linux lab computer. All source files submitted must compile and run on a Linux lab computer of the instructors choice. Submissions that do not compile on the Linux workstation will receive no compilation or execution/correctness points. 
You should submit only the following individual files to the assignment: problem1.cc 

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 that two valid integers will be input 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.cc source file, and sample input and output files have been provided to run initial tests on your program. You are encouraged to create more rigorous tests. To run the tests provided, create a directory containing only your problem1.cc file and the files extracted from the attached problem1tests.zip. Then type the following commands at the command prompt: 
 make problem1test1 make problem1test2 make problem1test3 

Points: style: 1 point clean compilation: 1 point execution / correctness (passes instructor tests): 2 points

checkit.cc

#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] '4' ) {

cout

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

correctchar = correctfile.get();

stuchar = studentfile.get();

while ( correctfile.good() && studentfile.good() && match ) {

match = correctchar == stuchar;

cout

if ( !match )

cout

(correctchar == '\t' ? "(a tab)" :

(correctchar == ' ' ? "(a newline)" : "")))

++i;

correctchar = correctfile.get();

stuchar = studentfile.get();

}

cout

if ( !match )

cout

else if ( !correctfile.eof() )

cout

else if ( !studentfile.eof() )

cout

else

cout

return 0;

}

makefile

# makefile for problem 1

#

# $@ target

# $

# $^ all prerequisites

flags = -std=c++17 -Wall -I .

problem1.o : problem1.cc

g++ $(flags) -c $

problem1 : problem1.o

g++ $(flags) $

checkit : checkit.cc

g++ $(flags) $^ -o $@

problem1test1 : checkit problem1 problem1-sample-input-1.txt

./problem1 problem1-student-output-1.txt

./checkit 0

problem1test2 : checkit problem1 problem1-sample-input-2.txt

./problem1 problem1-student-output-2.txt

./checkit 1

problem1test3 : checkit problem1 problem1-sample-input-3.txt

./problem1 problem1-student-output-3.txt

./checkit 2

clean :

rm *.o checkit problem1 problem1-student-output-*.txt

image text in transcribed

problem1-expected-output-1 Input sentence contains 23 alphabetic characters and 3 digits. problem1-expected-output-2 Input sentence contains 1 alphabetic character and 3 digits. problem1-expected-output-3 Input sentence contains 49 alphabetic characters and 0 digits. problem1-sample-output-1 I intend to earn a 100 on the exam. problem1-sample-output-2 1 u 2 . problem1-sample-output-3 This sentence is on multiple lines, which is interesting, no

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases And Information Systems 1 International Baltic Conference Dbandis 2020 Tallinn Estonia June 19 2020 Proceedings

Authors: Tarmo Robal ,Hele-Mai Haav ,Jaan Penjam ,Raimundas Matulevicius

1st Edition

303057671X, 978-3030576714

More Books

Students also viewed these Databases questions

Question

Using two op amps, design a subtractor?

Answered: 1 week ago