Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question: How do I program this? C Programming: A Modern Approach 2 nd edition by K.N. King, Lecture notes, slides and homework conducted to date

Question:

How do I program this?

C Programming: A Modern Approach 2ndedition by K.N. King, Lecture notes, slides and homework conducted to date

Palindrome.txt input file

DieWithError.c helper program

Makefile example file

C Coding Standards

ProgramTemp.c

Assignment: This assignment will be based upon the Programming Exercise in Chapter 12 #2 on page 275 and 276 of the reference text. (Snapshot from text provided below for your convenience):

Requirements:

The program should use the ProgramTemp.c as a coding template and incorporate the C Coding Standards to model a good product for turn-in. You will have points deducted if your code drifts too far from "sound" coding practices. If you have a serious issue with one of the standards... you need to indicate what it is in your README, what standard you will follow instead and then follow it throughout your coding.

The program should read all of the messages from a text file (Palindrome.txt) that will be provided. Within the Palindrome.txt are several palindromes and funny quotes I found that are not-palindromes. This will replace the need to accept a palindrome from the user.

The program should read the filename provided within the command line (see page 302 of the book)

Error conditions should be checked and sent to a helper program DieWithError.c that will also be provided for you. Implement error handling throughout your program and send these errors to the DieWithError.c helper program.

A minimum of the following errors should be checked:

Insufficient parameters on the command line

Cannot find or open the input file

Cannot output to the two output files

Empty input files (should expect at least one message in)

All characters of the input message should be evaluated, and if the beginning character of a word it should be made uppercase, if not the first character of a word then should be lower case. Obviously ignore any punctuation, spaces, and numerals i.e. non-alphabetic characters. Use the toupper() and tolower() (book page 614) and the associated header file to manipulate the characters prior to output to the screen or files.

For each message read: it should be printed to the screen with an indication of palindrome or not as the assignment indicates above (you can format as you see fit).

All palindromes should be placed into a new output file - palindromeOut.txt

All non-palindromes should be placed into a new output file - quotesOut.txt

Your program will need to utilize the header and at least 1 macro from this header within your main program

Your program must use pointers to keep track of position within arrays, and you must utilize an array to load and manipulate the messages. You do not have to use integers as indicated in the first part of the assignment above.

A final count should be printed prior to exit:

Total lines read in from the file Palindrome.txt

Total number of palindromes placed into palindromeOut.txt

Total number of quotes placed into quotesOut.txt

Your program will need to be compiled using the Unix/Linux/Mac "make" process and a Makefile that you will define. I will compile your program on either a Linux (Ubuntu) or Mac OS using gcc as the compiler and make to manage the compile (you choose which OS between those two options within your instructions). The makefile should be included in project files uploaded to Canvas. Recommend searching for "man make".

To turn in:

You will individually upload the following files:

README.txt - with instructions on which platform Linux - Ubuntu or MacOS to compile your project.

README should also include names of all programs and user-defined headers (if used) that I will need to compile.

Also, include instructions on directory structures. I am assuming that all directories will be relative i.e. you could define ../headers ../source ../output directories as relative to wherever I put them but DO NOT have a hardcoded directory structure i.e.: /users/bob/Documents/CS150/Project1/headers ... if you place everything in one folder and then assume that I will run make from within the same folder as all of the source files... this is more than sufficient.

README should also cover any issues, portions of the program that doesn't work or unexpected behavior that you were unable to resolve by the due date.

README should cover things that you had to work through/troubleshoot or which you did not understand at first

Source code files

User-defined headers - if used

Your modified makefile

Output files:

palindromeOut.txt

quotesOut.txt

Place screenshots into one document and then upload each file individually to Canvas associated with this Project 1 (i.e. no zip files)

Screenshots should show:

your code compiling without errors on your environment

your code being called with appropriate input parameters

output as it runs through the file's messages

the final output from the main program (with the totals)

snapshot of each output file (top few lines sufficient)

snapshots of tests to prove that error conditions specified above are being checked and properly sent to DieWithError.c

Note about Microsoft OS/Compilers IDE etc:

It is ok to code in the environment that you are comfortable with. That said if your IDE brings in items that are not standard to Unix/Linux/Mac then this may create issues. If you define directories in the Microsoft manner c:user... this will create issues unless you assume all will be run from the directory it is downloaded to.

The assignment implies that you have to ensure that this project compiles on a Unix/Linux/Mac environment.

As a reminder from the syllabus: (Grading Rubric)

Homework & Projects:

Homework and projects are coding assignments. As such, the following criteria will be used to assess performance. Continuous integration will be used to automatically compile submitted code and execute unit tests using documented input(s). Points per assignment will be awarded on a tiered schedule from the first to the fourth criterion below. Completing #1 is 25% of the total possible points, completing #1 and #2 is 50%, so forth and so on.

Your code compiles without error.

Your code executes without error.

Your code passes unit tests with expected output(s).

Your code is implemented using appropriate comments, standard conventions, idioms, and syntax.

ProgramTemp.c

/*=============================================================================

| Assignment: ASSIGNMENT NUMBER AND TITLE

|

| Author: STUDENT'S NAME HERE

| Language: NAME OF LANGUAGE IN WHICH THE PROGRAM IS WRITTEN AND THE

| NAME OF THE COMPILER USED TO COMPILE IT

| To Compile: EXPLAIN HOW TO COMPILE THIS PROGRAM (ie gcc ProgramTemp.c -o ProgramTemp.o)

| however we will get into makefiles later and if used should be referenced here)

|

| Class: NAME AND TITLE OF THE CLASS PROGRAM WAS WRITTEN FOR

| Instructor: NAME OF YOUR COURSE'S INSTRUCTOR

| Due Date: DATE AND TIME THAT THIS PROGRAM IS/WAS DUE TO BE SUBMITTED

|

+-----------------------------------------------------------------------------

|

| Description: DESCRIBE THE PROBLEM THAT THIS PROGRAM WAS WRITTEN TO

| SOLVE. IF FROM A BOOK REFER TO THE PAGE, CHAPTER AND ASSIGNMENT #

|

| Input: DESCRIBE THE INPUT THAT THE PROGRAM REQUIRES.

|

| Output: DESCRIBE THE OUTPUT THAT THE PROGRAM PRODUCES.

|

| Algorithm: IF USED; MAIN ALGORITHM OR ARITHMETIC EXPRESSION

|

| Known Bugs: IF THE PROGRAM DOES NOT FUNCTION CORRECTLY IN SOME

| SITUATIONS, DESCRIBE THE SITUATIONS AND PROBLEMS HERE.

|

*===========================================================================*/

//======== Begin of Headers ========

/*=========

| Why is the header(s) included? Generally only include what you need to reduce the overhead

|

*========*/

#include <>

//======== End of Headers ========

//======== Begin of Constants ========

/*=========

| What is the constant and what is it used for

|

*========*/

# define CONSTANT_VELOCITY 125

//======== End of Constants ========

//=========== Begin of Main ==============

int main(void) {

// main should be small with much of the work performed in functions

double userIn1, userIn2, functionOut;

userIn1=0, userIn2=0, functionOut=0;

functionOut=function1(userIn1, userIn2);

// some output would go here to use the function output and the constant defined above

return 0;

}

//=========== End of Main ==============

/*------------------------------------------------- FUNCTION_NAME -----

| Function FUNCTION_NAME

|

| Purpose: EXPLAIN WHAT THIS FUNCTION DOES TO SUPPORT THE CORRECT

| OPERATION OF THE PROGRAM, AND HOW IT DOES IT.

|

| Parameters:

| parameter_name (IN, OUT, or IN/OUT) -- EXPLANATION OF THE

| PURPOSE OF THIS PARAMETER TO THE FUNCTION.

| (REPEAT THIS FOR ALL FORMAL PARAMETERS OF

| THIS FUNCTION.

| IN = USED TO PASS DATA INTO THIS FUNCTION,

| OUT = USED TO PASS DATA OUT OF THIS FUNCTION

| IN/OUT = USED FOR BOTH PURPOSES.)

|

| Returns: IF THIS FUNCTION SENDS BACK A VALUE VIA THE RETURN

| MECHANISM, DESCRIBE THE PURPOSE OF THAT VALUE HERE.

*-------------------------------------------------------------------*/

//=========== Begin of Function function1 ==============

double function1(double in1, double in2) {

return ((in1+in2)/2);

}

//=========== End of Function function1 ==============

Makefile

CC = gcc

CFLAGS = -g -Wall

INCLUDE1=DieWithError.c

INCLUDE2=DieWithError.c HandleClientTCP.c

all: EchoClientTCP EchoServerTCP

EchoClientTCP: EchoClientTCP.c

$(CC) $(CFLAGS) $(INCLUDE1) -..$@.o $<

EchoServerTCP: EchoServerTCP.c

$(CC) $(CFLAGS) $(INCLUDE2) -..$@.o $<

clean:

-rm -f *.o *~ *core*

DieWithError.c

#include /* for perror() */

#include /* for exit() */

void DieWithError(char *errorMessage)

{

perror(errorMessage);

exit(1);

}

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

Progress Monitoring Data Tracking Organizer

Authors: Teacher'S Aid Publications

1st Edition

B0B7QCNRJ1

More Books

Students also viewed these Databases questions