All of the work in this project is my own! I have not left copies of my code in public folders on university computers. I have not given any of this project to others. I will not give any portion of this project to others taking this class. I realize that the penalty for turning in work that is not my own can range from an "F" in the class to dismissal from Trinity University.
Print Title ______________________________________ Time Required = ______.____ Hrs.
Signature ______________________________________ (pledged)
1] Copy ???-HW5.c to ???-HW6.c Copy (replace ??? with your first name. - I would use Tom-HW6.c)
2] Include the following:
# include
<stdio.h># include
<string.h># include
<stdlib.h># include
<stdbool.h>
1] Documentation your main program (replace the name and date appropriately!)

//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
// GetInt //
// //
// Purpose : (1) If Clear is true, then clear the terminal window; otherwise //
// don't. //
// //
// (2) Print the prompt; to the right of the prompt add //
// [Hit ENTER Key To Exit!]. For the function call: //
// GetInt("Enter Exam 2", Exam2, 0,100,false) //
// the user should see ==> Enter Exam 2 [Hit ENTER Key To Exit!] : //
// //
// (3) Declare char TempString[100]; //
// It is now time for the user to respond to the prompt. Use gets //
// to fill the string container called TempString. //
// //
// (4) If the USER simply hits the ENTER key, return false. //
// //
// (5) Check to see if the USER enters a non-numerical value //
// (maybe use atoi and our own itoa to verify that the number //
// is indeed numeric) //
// //
// gets(IntStr) User enters "1234" IntStr = "1234" //
// TempInt = atoi(TempString) TempInt = 1234 //
// itoa(TempString, TempInt); TempString = "1234" //
// strcmp(IntStr,TempString) = 0 Therefore Number OK //
// //
// gets(IntStr) User enters "12A4" IntStr = "12A4" //
// TempInt = atoi(TempString) TempInt = 12 //
// itoa(TempString, TempInt); TempString = "12 " //
// strcmp(IntStr,TempString) != 0 Therefore Number !OK //
// //
// If the number is not ok print an error message: //
// "\n\nYou Have Entered Invalid Data!\n" //
// Return to step (2) and repeat all of the steps. //
// Do not ever use a GoTo command! //
// //
// (6) The number is valid thus far. Check to see if the TempInt //
// is less than the Low. //
// //
// If the number is not ok print an error message: //
// "\n\nYour Entry Is Too High - Enter A "); //
// "Value [0 - 100]!\n\n" //
// Return to step (2) and repeat all of the steps. //
// Do not ever use a GoTo command! //
// //
// (7) The number is valid thus far. Check to see if the TempInt //
// is greater than the High. //
// //
// If the number is not ok print an error message: //
// "\n\nYour Entry Is Too High - Enter A "); //
// "Value [0 - 100]!\n\n" //
// Return to step (2) and repeat all of the steps. //
// Do not ever use a GoTo command! //
// //
// (8) Transfer the contents of TempInt to *Int (after all //
// you now know that it is the correct datatype and within //
// the acceptable range. //
// //
// (7) Return true. //
// //
// //
// Written By : Thomas E. Hicks Environment : Linux //
// Date ......: xx/xx/xxxx Compiler ...: gcc //
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////


1] Unfortunately the approach for verifying correct floating point numbers can not easily be done with atof and ftoa functions. This is because floating point numbers are approximatations.
atof("12.34") might be 12.340001 or 12.339997. They are approximations that are reasonably close. If you want greater precision, use double.
2] You may simply copy and paste the following ValidFloatStr function and use it for your lab.
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
// ValidFloatStr //
// //
// Purpose : Explicitly return true if the String is a valid Float. //
// return false. //
// //
// Written By : Thomas E. Hicks Environment : Linux //
// Date ......: xx/xx/xxxx Compiler ...: gcc //
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
bool ValidFloatStr(char String[])
{
bool
Valid = true;
int
Pos,
NoDecimalPoints = 0;
// First character must be + or - or digit
if ((String[0] != '+') && (String[0] != '-') && (isdigit(String[0]) == 0) )
return (false);
// Must only be one decimal point in the number
for (Pos = 0; Pos < strlen(String); Pos ++)
if (String[Pos] == '.')
NoDecimalPoints++;
if (NoDecimalPoints > 1)
return (false);
// Characters 2, 3, 4, ... must be either a digit or a decimal point
for (Pos = 1; Pos < strlen(String); Pos ++)
if ( (String[Pos] != '.') && (isdigit(String[Pos]) == 0))
return (false);
return(Valid);
}
1] You may Copy and paste the documentation.
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
// GetFloat //
// //
// Assumptions : You may assume that our user must enter the decimal point! //
// You may assume use enters no more than four digits to right //
// of the decimal point. //
// Purpose : (1) If Clear is true, then clear the terminal window; otherwise //
// don't. //
// //
// (2) Print the prompt; to the right of the prompt add //
// [Hit ENTER Key To Exit!]. For the function call: //
// GetFloat("Enter Exam 2", Exam2, 0,100,false) //
// the user should see ==> Enter Exam 2 [Hit ENTER Key To Exit!] : //
// //
// (3) Declare char TempString[100]; //
// It is now time for the user to respond to the prompt. Use gets //
// to fill the string container called TempString. //
// //
// (4) If the USER simply hits the ENTER key, return false. //
// //
// (5) Check to see if the USER enters a valid Float string. //
// //
// Use the ValidFloatStr(FloatStr) function I have provided. //
// If the number is not ok print an error message: //
// "\n\nYou Have Entered Invalid Data!\n" //
// Return to step (2) and repeat all of the steps. //
// Do not ever use a GoTo command! //
// //
// (6) The number is valid thus far. Check to see if the TempFloat //
// is less than the Low. //
// //
// If the number is not ok print an error message: //
// "\n\nYour Entry Is Too High - Enter A "); //
// "Value [0 - 100]!\n\n" //
// Return to step (2) and repeat all of the steps. //
// Do not ever use a GoTo command! //
// //
// (7) The number is valid thus far. Check to see if the TempFloat //
// is greater than the High. //
// //
// If the number is not ok print an error message: //
// "\n\nYour Entry Is Too High - Enter A "); //
// "Value [0 - 100]!\n\n" //
// Return to step (2) and repeat all of the steps. //
// Do not ever use a GoTo command! //
// //
// (8) Transfer the contents of TempFloat to *Float (after all //
// you now know that it is the correct datatype and within //
// the acceptable range. //
// //
// (7) Return true. //
// //
// //
// Written By : Thomas E. Hicks Environment : Linux //
// Date ......: xx/xx/xxxx Compiler ...: gcc //
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
int main (int argc, char * argv[])
{
char
Name[12];
int
Age,
Ex1,
Ex2;
float
SemAvr;
puts ("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
puts ("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
puts ("++ Utility Functions HW5 ++");
puts ("++ ++");
puts ("++ Writen By ++");
puts ("++ ???????????????????? ++");
puts ("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
puts ("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
puts ("\n======================== Start Of Main ========================\n");
if ( (GetString("Enter Name", Name, 12, true)) &&
(GetInt("Enter Age", &Age, 1, 30, false)) &&
(GetInt("Enter Exam 1 Grade", &Ex1, 0, 100, false)) &&
(GetInt("Enter Exam 2 Grade", &Ex2, 0, 100, false)) &&
(GetFloat("Enter Semester Average", &SemAvr, 0.0, 100.0, false)) )
{
printf("\n\n");
printf("Name ....= %s\n", Name);
printf("Age .....= %d\n", Age);
printf("Ex1 .....= %d\n", Ex1);
printf("Ex2 .....= %d\n", Ex2);
printf("SemAvr ..= %f\n", SemAvr);
}
else
puts ("You Chose Not To Provide All Of Our Information!");
puts ("\n========================= End Of Main =========================\n");
return (0);
}
|
1] I recommend that you write one function at a time. Test it! Once it works well, move on to the next function. You can do this by un-commenting out one small portion of the main program at a time until the whole main program is un-commented.
1] Among the many things you test, you might try the following data inputs:

1] Copy file tom-HW6.c to
/users/thicks/hw1320/hw61] Signed copy of page 1 of this Lab.
2] Printed copy of the source code.
3] Nothing will be graded until you copy the file into the /users/thicks/hw1320 directory.
4] Nothing will be graded until this lab form is submitted. Staple the pages. Fold the lab Horizontally (like a hot dog) and write your name nice and large on the outside. Place it on the professor desk before the beginning of lecture on the day it is due. All assignments are due the next class period unless otherwise designated on the schedule page.