Hire Experts For Answers
Order NowRelated Study Services
- Homework Answers
- Coursework writing help
- Term paper writing help
- Writing Help
- Paper Writing Help
- Research paper help
- Thesis Help
- Dissertation Help
- Case study writing service
- Capstone Project Writing Help
- Lab report Writing
- Take my online class
- Take my online exam
- Do my test for me
- Do my homework
- Do my math homework
- Online Assignment Help
- Do my assignment
- Essay Writing Help
- Write my college essay
- Write my essay for me
DESCRIPTION
Posted
Modified
Viewed
20
I just need the working code and answers. The answer document I can do my self and extra credit at the bottom question 6 and 7 you don't have to do. This is for intro to computer science class for C programming.
This order does not have tags, yet.
Attachments
/******************************************************************************
* CSE 1310 Fall 2022
* File name: DrTLab3.c
* Author : Dr. Tiernan
* Created on: 22 Oct 22
*
* UTA Student Name: J C M Tiernan
* UTA ID: 100000000
*******************************************************************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
//#define DEBUG 1
const int BOTMAX = 30; // maximum number of robots
const int STRMAX = 50; // maximum length of string
const int INTMAX = 3; // number of integer array columns
const int STRCOLMAX = 5; // number of string array columns
const int YR = 0; // year column in int array
const int CST = 1; // cost column in int array
const int HT = 2;
const int NAME = 0;
const int KIND = 1;
const int COST = 2;
const int TITLE = 3;
const int SWORD = 4;
void prtSep(char sep,int cnt);
int checkKind(char kind[STRMAX]);
long int checkCost(char cost[STRMAX]);
int rSW(char src, char source[STRMAX]);
int emptyTables(char botDataStr[BOTMAX][STRCOLMAX][STRMAX],
double botInt[BOTMAX][INTMAX],char botSrc[BOTMAX]);
void printBotSent(char botDataStr[BOTMAX][STRCOLMAX][STRMAX],
double botInt[BOTMAX][INTMAX],char botSrc[BOTMAX], int botCnt);
void printBotTbl(char botDataStr[BOTMAX][STRCOLMAX][STRMAX],
double botInt[BOTMAX][INTMAX],char botSrc[BOTMAX], int botCnt);
void remBlanks(char st[STRMAX]);
int main()
{
// The input data will come from a file called “robotInfoL3.txt”
char fileName[] = "robotInfoL4.txt";
FILE *inRobots = fopen(fileName, "r");
/*
Declare 1-dimensional arrays to hold pieces of data from a file.
Arrays should contain a maximum of 30 robots from the input file.
Max array size should be declared with a global constant (BOTMAX).
word integer word double character word multi-word-string
Ex. C3PO 1977 humanoid 5.75 M 11M Star Wars
The meanings of the each piece of data are as follows:
robotName robotYear robotKind robotHeightFt robotSource robotCost
robotSourceTitle
Ex. Opportunity 2004 aerospace 4.9 R 400M NASA
Name the arrays with meaningful names.
char botNms[BOTMAX][STRMAX]; // STRMAX is max length of any string input
char botKnd[BOTMAX][STRMAX];
char botCost[BOTMAX][STRMAX];
char botTtl[BOTMAX][STRMAX];
char botSrcWd[BOTMAX][STRMAX];
*/
// constants declared for the table columns:
// NAME = 0; KIND = 1; COST = 2; TITLE = 3; SWORD = 4;
char botDataStr[BOTMAX][STRCOLMAX][STRMAX];
double botInt[BOTMAX][INTMAX]; // column 0 is YR, col 1 is CST, col 3 = HT in ft
char botSrc[BOTMAX];
char tmpNum[STRMAX];
char tmpWd[STRMAX];
char inBuffer[128];
int botCnt = 0;
int strCnt = 0;
int dataInvalid = 0; // flag that is TRUE when data is INVALID
//emptyArrays(botNms, botInt, botKnd, botSrc, botCost, botTtl, botSrcWd );
emptyTables(botDataStr, botInt, botSrc);
/*
Read one line at a time into the program using fgets (will need loop)
Read individual values from the string using sscanf.
Values read from string should be stored into the arrays
All values from same row of file stored at same index in each array.
*/
printf("The original data from the file is:\n\n");
printf(" %-28s ","Title");
printf("%-10s %-28s %4s %4s %-19s %4s %10s\n",
"Source","Name","HtFt", "Year","Kind","Cost","$Amt");
prtSep('-',120);
while (!feof(inRobots))
{
dataInvalid = 0;
fgets(inBuffer, 128, inRobots);
#ifdef DEBUG
printf("Line from file: %s\n", inBuffer); // debug
#endif
sscanf(inBuffer, "%[^0-9]s",
botDataStr[botCnt][NAME] );
strCnt = strlen(botDataStr[botCnt][NAME]);
// What if name has a digit in it? C-3PO?
sscanf(inBuffer, "%s", tmpWd ); // reread with space delimiter
if (strlen(tmpWd) > strCnt) // if string read with %s is longer, save it
{
strcpy(botDataStr[botCnt][NAME],tmpWd);
#ifdef DEBUG
printf("Name copied from tmpWd: %s\n",botDataStr[botCnt][NAME]);
#endif
}
strCnt = strlen(botDataStr[botCnt][NAME]); // where did this name end?
remBlanks(botDataStr[botCnt][NAME]);
// start scanning again at the location after the name string
// &(inBuffer[strCnt]) gets the address of the char following the name string
sscanf(&(inBuffer[strCnt]), "%lf %s %lf %c %s %[^\n]s",
&botInt[botCnt][YR],
botDataStr[botCnt][KIND],
&botInt[botCnt][HT],
&botSrc[botCnt],
botDataStr[botCnt][COST],
botDataStr[botCnt][TITLE] );
remBlanks(botDataStr[botCnt][KIND]);
remBlanks(botDataStr[botCnt][TITLE]);
#ifdef DEBUG
printf("Name: %s\n",botDataStr[botCnt][NAME]);
printf("Year: %ld\n",botInt[botCnt][YR]);
printf("Title: %s\n",botDataStr[botCnt][TITLE]);
#endif
/*
Check that the year value meets the valid range of years as given above
and print an error message is the year is out of range.
*/
if ((botInt[botCnt][YR] < 1900) || (botInt[botCnt][YR] > 2023))
{
printf("\n**INVALID: Robot %s year %.0lf is out of range 1900 to 2023\n",
botDataStr[botCnt][NAME], botInt[botCnt][YR]);
dataInvalid = 1;
}
/*
Call function checkCost after year verification test
Save return value in cost column in the integer array.
If checkCost returns -1,
print an error message indicating that the robotCost value was invalid.
*/
botInt[botCnt][CST] = checkCost(botDataStr[botCnt][COST]);
if (botInt[botCnt][CST] == -1)
{
printf("\n**INVALID: Robot %s cost string %s is invalid format \n",
botDataStr[botCnt][NAME], botDataStr[botCnt][COST]);
dataInvalid = 1;
}
/*
The function checkKind should be called in main after the year and
cost validation. If the returned value is 0, then 1) an error
message should be printed indicating that the input robot kind
was not valid and 2) the word “unknown” should be stored as the
robot kind.
*/
if (checkKind(botDataStr[botCnt][KIND]) == 0)
{
printf("\n**INVALID: Robot %s kind \"%s\" is invalid value \n",
botDataStr[botCnt][NAME], botDataStr[botCnt][KIND]);
strcpy(botDataStr[botCnt][KIND], "unknown");
dataInvalid = 1;
}
/*
After one line of values has been stored, print the data from the arrays
in the format shown below.
Star Wars movie C3PO 1977 humanoid 11M
NASA real life Opportunity 2004 aerospace 400M
This format is:
robotSourceTitle robotSourceWord robotName robotYear robotKind robotCost
where
robotSourceWord is the full word or phrase represented by the
robotSource character in the array
Use a function to find and return the correct word/phrase given the
robotSource character and an empty 20 character string as input
parameters. The program should read from the file until all the
data has been read and stored in the arrays.
*/
int result = rSW(botSrc[botCnt],botDataStr[botCnt][SWORD]);
if (result == 0)
{
printf("\n**INVALID: Robot %s source letter %c is invalid\n",
botDataStr[botCnt][NAME], botSrc[botCnt]);
dataInvalid = 1;
}
if (botInt[botCnt][HT] <= 0)
{
printf("\n**INVALID: Robot %s height %.2lf is an invalid value \n",
botDataStr[botCnt][NAME], botInt[botCnt][HT]);
dataInvalid = 1;
}
sprintf(tmpWd, "%.0lf", botInt[botCnt][CST]);
#ifdef DEBUG
printf("tmpWd =*%s*\n",tmpWd);
#endif
printf("%2d) %-28s ",botCnt+1, botDataStr[botCnt][TITLE] );
printf("%-10s %-28s %4.2lf %4.0lf %-19s %4s %10s\n",
botDataStr[botCnt][SWORD] ,
botDataStr[botCnt][NAME] ,
botInt[botCnt][HT],
botInt[botCnt][YR],
botDataStr[botCnt][KIND],
botDataStr[botCnt][COST],
( botInt[botCnt][CST] > 0 ? tmpWd : " ")
);
if (dataInvalid == 0)
botCnt++;
else
printf("\n"); // puts a blank line after data with an error
} // end of while !feof
/*
After data is read and stored, use a loop to print the data
in a set of sentences showing all data in the arrays.
Do not print empty array elements. Ex.
C3PO is a/an humanoid robot costing 11M from the 1977 Star Wars movie
OR
NASA created aerospace robot Opportunity in 2004 for 400M in real life
*/
printBotSent(botDataStr, botInt, botSrc, botCnt);
// write function to print table
printBotTbl(botDataStr, botInt, botSrc, botCnt);
return 0;
}
void printBotSent(char botDataStr[BOTMAX][STRCOLMAX][STRMAX],
double botInt[BOTMAX][INTMAX],char botSrc[BOTMAX], int botCnt)
{
printf("\n\nThe valid robots from the file:\n");
for (int r=0; r < botCnt; r++)
{
printf("%2d. %s %s %s created %4.2lf' %s robot %s for %s (or $%.0lf) in
%.0lf\n", r+1,
((botSrc[r] == 'R')? "In" : "The"),
botDataStr[r][SWORD],
botDataStr[r][TITLE] ,
botInt[r][HT],
botDataStr[r][KIND],
botDataStr[r][NAME] ,
botDataStr[r][COST],
botInt[r][CST],
botInt[r][YR] );
}
}
void printBotTbl(char botDataStr[BOTMAX][STRCOLMAX][STRMAX],
double botInt[BOTMAX][INTMAX],char botSrc[BOTMAX], int botCnt)
{
printf("\n\nThe valid robots table:\n");
printf(" %-28s ","Name");
printf("%4s %-10s %-28s %-19s %4s %4s %10s\n",
"Year","Source","Source Title","Kind","HtFt","Cost","$Amt");
prtSep('-',120);
for (int r=0; r < botCnt; r++)
{
printf("%2d] %-28s ",r+1, botDataStr[r][NAME] );
printf("%4.0lf %-10s %-28s %-19s ",
botInt[r][YR],
botDataStr[r][SWORD] ,
botDataStr[r][TITLE] ,
botDataStr[r][KIND]);
if (((int)(botInt[r][HT]*100) % 10) != 0)
printf("%4.2lf ", botInt[r][HT]);
else if (((int)(botInt[r][HT]*10) % 10) != 0)
printf("%4.1lf ", botInt[r][HT]);
else
printf("%4.0lf ", botInt[r][HT]);
printf("%4s %10.0lf\n",
botDataStr[r][COST],
botInt[r][CST]);
}
}
/*
For this part you will adding a function to validate that the value
of the robot kind matches one of the allowed types given in the
description above. The function should be called checkKind and
should take in the robot kind value as input. The output should
be either a 0 if the kind did not match or a number representing
which kind was matched in alphabetical order. The function
checkKind should use nested if-else commands and string comparison
to determine if the string is valid.
1. aerospace 9. humanoids
2. consumer 10 industrial
3. disasterResponse 11 medical
4. drones 12 militarySecurity
5. education 13 research
6. entertainment 14 selfDrivingVehicles
7. exoskeletons 15 telepresence
8. fictional 16 underwater
*/
int checkKind(char kind[STRMAX])
{
int val = 0;
if (strcmp(kind, "aerospace") == 0)
val = 1;
else if (strcmp(kind, "consumer") == 0)
val = 2;
else if (strcmp(kind, "disasterResponse") == 0)
val = 3;
else if (strcmp(kind, "drones") == 0)
val = 4;
else if (strcmp(kind, "education") == 0)
val = 5;
else if (strcmp(kind, "entertainment") == 0)
val = 6;
else if (strcmp(kind, "exoskeletons") == 0)
val = 7;
else if (strcmp(kind, "fictional") == 0)
val = 8;
else if (strcmp(kind, "humanoid") == 0)
val = 9;
else if (strcmp(kind, "industrial") == 0)
val = 10;
else if (strcmp(kind, "medical") == 0)
val = 11;
else if (strcmp(kind, "militarySecurity") == 0)
val = 12;
else if (strcmp(kind, "research") == 0)
val = 13;
else if (strcmp(kind, "selfDrivingVehicles") == 0)
val = 14;
else if (strcmp(kind, "telepresence") == 0)
val = 15;
else if (strcmp(kind, "underwater") == 0)
val = 16;
return val;
}
/*
Write a function, called checkCost, that will verify the robotCost
string and return a number. The robotCost string should be the
input parameter. The return value will either be -1 to indicate
that the cost string is invalid or it will be the numeric value
indicated by the cost string which must be greater than 0.
In the function checkCost, the verification of the cost string
should check that the string has one letter (‘M’, ‘B’, or ‘K’)
at the end and that all the other characters in the string are
digits or a period (decimal point).
If the string is determined to be valid, then calculate the value
the string represents. If the string is invalid, return a -1
from the function.
For a valid string, calculate the numeric value by converting
the digit part of the string to a number and then multiplying
that number by a thousand (K), a million (M), or a billion (B).
Return this numeric value as the result of the function.
[Pulling out the digit part of the string is the fun part of this.]
*/
long int checkCost(char cost[STRMAX])
{
char numStr[STRMAX];
double numCost = 0;
int numLen = 0;
char denom = ' ';
int val = -1;
#ifdef DEBUG
printf("In checkCost, input string is %s\n",cost);
#endif
sscanf(cost,"%[^A-Z]s", numStr);
numCost = atof(numStr);
#ifdef DEBUG
printf("In checkCost, numStr is *%s* and numCost is %lf\n",numStr,numCost);
#endif
if (numCost > 0)
{
numLen = strlen(numStr);
denom = cost[numLen];
#ifdef DEBUG
printf("In checkCost, strlen(numStr) is %d and denom is %c\n",
numLen,denom);
#endif
switch (denom)
{
case 'K': numCost *= 1000; break;
case 'M': numCost *= 1000000; break;
case 'B': numCost *= 1000000000; break;
default: numCost = -1; break;
}
#ifdef DEBUG
printf("In checkCost, after switch numCost is %.0lf\n",numCost);
#endif
}
else
numCost = -1;
return (long int) numCost;
}
int rSW(char src, char source[STRMAX])
{
/*
robotSource - a single character that gives the type of source the
robot comes from. The valid types of sources are:
B – book
M - movie
P - play
R – real life
T – TV show
*/
int validSrc = 1;
switch(src)
{
case 'B':
{
strcpy(source, "book");
break;
}
case 'M':
{
strcpy(source, "movie");
break;
}
case 'P':
{
strcpy(source, "play");
break;
}
case 'R':
{
strcpy(source, "real life");
break;
}
case 'T':
{
strcpy(source, "TV show");
break;
}
default:
{
strcpy(source, "not known");
validSrc = 0;
break;
}
}
return validSrc;
}
int emptyTables(char botDataStr[BOTMAX][STRCOLMAX][STRMAX],
double botInt[BOTMAX][INTMAX],char botSrc[BOTMAX])
{
for (int i=0; i < BOTMAX; i++)
{
for (int d=0; d < STRCOLMAX; d++)
strcpy(botDataStr[i][d]," ");
for (int c=0; c < INTMAX; c++)
botInt[i][c] = 0;
botSrc[i] = ' ';
}
return 1;
}
void remBlanks(char st[STRMAX])
{
int len = strlen(st);
while(isspace(st[len-1]))
{
len--;
}
st[len] = '\0';
while (isspace(st[0]))
{
for (int i=0; i<len; i++ )
st[i] = st[i+1];
len--;
}
}
void prtSep(char sep,int cnt)
{
for (int i=0; i<cnt; i++)
printf("%c",sep);
printf("\n");
}
Elsie 1948 research 1 R 28K Dr. William Grey Walter
Tessman 2008 entertainment 6 P 750K Heddatron
Golden Maidens 449 fictional 4.8 B 1K Hephaestus
C-3PO 1977 humanoid 5.75 M 11M Star Wars
Wall-E 2008 disasterResponse 2.5 M 180M WALL-E
Rossum's Universal Robots 1921 satire 7.75 P 50K Karel Capek
Kitt 1982 selfDrivingVehicles 4.25 T 150K Knight Rider
BB8 2015 fictional 2.2 M 245M Star Wars The Force Awakens
Astro Boy 1952 humanoid 4.5 B 298M Mighty Atom
Spot 2020 consumer 2 R 74K Boston Dynamics
TinMan 1900 fictional 5.8 B K L. Frank Baum
Opportunity 2004 aerospace 4.9 R 400M NASA
Johnny-5 1986 militarySecurity 6 M 9M Short Circuit
Rosie 1962 fictional 6.5 T 300K The Jetsons
Myon 2015 entertainment -4 P 500K My Square Lady
Marvin the Paranoid Android 1978 fictional 3.5 B 5K The Hitchhiker's Guide TTG
Robby 1939 fictional 7 M 1.9M Forbidden Planet
Aibo 1999 consumer 0.8 E 1.8K Sony
Dr. Soji Asha 2021 humanoid 5.33 T 3B Star Trek Picard
Unimate 1961 industrial 4.66 R 100K GM
The Robot 1965 fictional 6.55 T 75K Lost In Space
Tik-Tok 1907 fictional 4.9 B 43 L. Frank Baum
Baymax 2014 medical 6.16 M 165M Big Hero Six
CSE 1310 – Fall 22
Introduction to Programming
Lab 4
Deadline:
This Lab has a firm deadline. There will be no late extensions.
***Extra credit for early submission:
Submitted 24 hours (1 day) early + 5 points extra
Submitted 48 hours (2 days) early + 10 points extra
Submitted 96 hours early (4 days) + 20 points extra
Purpose:
This Lab 4 assignment is to have you practice with some substantial code that is already written as well
as write some code that combines most of the concepts we have discussed this semester. You will
review and understand a medium sized program and you will add significant modifications to this
program to perform searching and sorting on the arrays. You will continue to build on the skills you
have learned from the previous lab assignments. All of these tasks will increase your facility with
programming. Remember that the lab is in parts. If you cannot complete all the parts or all questions
within a part but you have some completed and working, then you can submit incomplete working
programs for pieces of the lab. This will give you partial credit.
Grading
The Lab assignment will be graded out of 100 points. There are multiple parts or tasks that make up
each Lab. Each part may have multiple tasks or problems to complete. Each task has a point value
associated with it. Your lab is due on the DUE date in Canvas. The availability date is only for late
assignments. Remember that you may ALSO choose to turn in a partial working lab for partial credit.
You can still receive credit this way.
[Same as previous Lab]
Instructions for naming the folders and files that you create for this lab assignment:
This assignment requires you to create a variety of files and folders: code files (your programs), edited
files (your answer document), and a submission folder to store all the documents in that you must
submit. Each of these files/folders will be named using a naming convention that makes it easy to
distinguish which elements belong to which student. For each of these files/folders the instructions
will indicate how to name the item. You will see names like XYZ1234Lab4answers,
XYZ1234Lab1Part2, or XYZ1234Lab3.
In each of these names you see "XYZ1234". This is a placeholder for you to put in your initials and the
last four digits of your ID number, i.e. "XYZ" gets replaced with your initials and "1234" gets replaced
with the last four digits of your UTA ID number. So if I see an instruction that says " Create a NEW C
application, i.e. a new C project, called XYZ1234Lab1Part2… " and my initials are JCMT and the last
four digits of my ID are 1234, then the file that I should create would be named JCMT1234Lab1Part2.
Note that you can use however many initials you have to replace the "XYZ". I use 4 initials so that is
what I put; if you use two initials "MW", then replace "XYZ" with "MW". You must use exactly 4 digits
from the end of your ID to replace 1234.
Don't change any other part of the given file name. If it says XYZ1234Lab1Part2 and you are ABC and
5678 then your file name must be ABC5678Lab1Part2. It cannot be ABC5678Part2 or ABC567812 or
ABC5678LabOnePartTwo etc.
Any file that is incorrectly named will receive a 5 point deduction for the whole lab assignment. The
total penalty is 5 points no matter how many files are named incorrectly.
Naming summary: Use your initials and your last 4 digits of ID in place of "XYZ1234" in the given file
names. Keep all the rest of the name as defined.
[Same as previous Lab]
Instructions about the folder that will contain the files required for the Lab:
For every lab assignment you need to create ONE lab folder. In this lab folder you will put all of the
individual files that you need to submit for the lab assignment. The folder should be named with your
initials, your last 4 digits, and LabX. [If you don’t have your files organized into folders, I STRONGLY
suggest that you start doing this. This is a way to sort the material you keep on your computer and be
able to find it later. Check the internet for suggestions on how to do this type of organization.)
As an example, if your name is Happy Camper with UTA ID 1000101010, then your Lab 1 folder name is
HXC1010Lab1. You will save all the files that are part of the assignment into this folder. Once you have
put all the needed .c files in your folder, you will zip the folder to compress it before submitting it (see
info further down with submission details).
If the folder is incorrectly named you will receive a 5 point deduction for the whole lab assignment.
[Same as previous Lab]
Instructions about the Answers document required for the Lab:
For every lab assignment you need to create ONE Answers file. In this Answers file you will put in the
answers any questions that are asked, you will show the output of code that you write and you will
reference any code files that you create for a given question. All answers/outputs etc. go into the
same answers document.
• Your answers document needs to be named with your initials and the last four digits of your ID
number and then Lab#Answers. So if my initials are JCMT and the last four digits of my ID are
1234, then the answers file for my Lab 4 would be JCMT1234Lab4Answers. [-5 deduction if
incorrectly named]
• The ONLY acceptable file formats for the answers doc are Word document (.docx), OpenOffice
document(.odt), and PDF (.pdf). {-20 pt deduction if a different but readable format is used. -
100 pt deduction if file cannot be read because of the file format.}
• Put your last name, first name and UTA ID in the file on the first line. [-5 deduction if not]
• Label the answers for each question with the number/letter of the question. Separate each
answer from the next answer by at least two blank lines if your document is single spaced OR
separate answers with at least one blank line if paragraphs have spacing between them in their
formatting. [-5 deduction if not]
• Include EVERY question number/letter combination from the assignment in your answers
document. If the question is a coding question telling you to save a file, for example some
question numbered 17.b), then in your answers document you should have a line like the
following for question 17.b):
17.b) Please see file XYZ1234Lab1Part3.c for this question.”
Missing questions in the answer file will result in zero points for that question even if an
appropriate file/document is in the lab folder for this question. For example, if question 17.b
(from above) were omitted from the answer document and file XYZ1234Lab1Part3.c were
included in the folder, the question 17.b would get zero points (0) because it's answer was not
in the answer document.
• Put all your question answers for a lab into the same Answer document for that lab.
• If the lab question asks you to show the output of a doing some particular thing with the code,
then you must include a screenshot of the output in the Answer document, i.e. paste in a
screenshot picture of the output. For output that takes up more than one screen, make
multiple pictures so that every screen is recorded. If you do not include the screenshots in your
answer document, then the questions that should have had screenshots will be considered
“Not answered” and will be awarded ZERO 0 points. If screenshots are too small to read
comfortably or contain incorrect data, then a deduction of at least 50% of the points will be
made.
Each task below will instruct you on what type of "answer" is required for that part of the current
problem. If the task says to “Save your program as file XYZ1234Lab1Task1.c” then this .c file should
be turned in as part of the assignment and the appropriate reference to the .c file should be put in the
answers file as described previously.
[Same as previous Lab]
Instructions about C files, i.e. the .c documents:
In parts of the lab assignment you will be directed to create C programs, i.e. .c files. Your C program
will be named main.c by the onlineGDB system. However, when you save the file and when you put a
file name in the header block (both described below) you should name your file with the name
specified in the question you are answering. Likewise, when you download the .c file from onlineGDB
you will save it with the name that you have specified rather than saving the file as the default main.c.
Any file that is incorrectly named will receive a 5 point deduction for the whole lab assignment. The
total penalty is 5 points no matter how many files are named incorrectly.
C file header blocks
At the very top of every C file that you create you must put in the following header comment block
with the labels shown below for information:
/******************************************************************************
* CSE 1310 Spring 2022
* File name:
* Author :
* Created on:
.*
* UTA Student Name:
* UTA ID:
*******************************************************************************/
In this block you will fill in the name of the file that you are creating, the author name (this is the name
that you are logged in as), the date that the file was created, your name as UTA records it, and your 10
digit UTA ID number. This block should be before the first #include statement in your code. (Note that
you do not have to have an entire line of asterisks at top and bottom. You can have /* on the first line
and */ on the last line if desired.)
The IDE you use may have a comment block at the top of your code. You may remove any comment
information that is not useful to your assignment. You must put in the labels and information listed
above:
Any .c file that is missing a header block will receive a 7 point deduction for the whole lab assignment.
The total penalty is 7 points no matter how many header blocks are missing (one, some, or all).
Example: As an example, here is a header block for one of my files
/******************************************************************************
* File: main.c
* Author: jcmtiernan
* Created on: January 15, 2022, 12:57 PM
.*
* UTA Student Name: Dr. Carter Tiernan
* UTA ID: 1000000000
*******************************************************************************/
#include <stdio.h>
Additonally, you should add a comment block before main, that adds comments to describe your
program. Here is an example
/***********
* Lab X Part Y – Testing arithmetic in C
***********/
int main…
Be sure to follow the naming conventions for any code file you create.
There are further instructions at the bottom (after the questions) about how to save the .c files you
create in order to be able to turn it in.
Instructions about data files, i.e. the .txt documents:
In parts of the lab assignment you will be directed to create new data files, i.e. input .txt files for your
program. You should use any naming conventions given in the problem. The data files you create will
be saved along with the answers document and the .c files into the lab folder that you will submit.
Summary of answer document and .c files prep
1 Create an Answers file named with your initials and the last four digits of your ID number and then
Lab#Answers that is of file type .docx, .pdf, or .odt; ex. XYZ1234Lab3Answers.docx
2 Put lastname, firstname and UTA ID on the first line; then put every question number into the file.
3 Make sure to put an answer or comment after every question number. The answer might be a
written answer, a pasted pic or screenshot, or a message indicating that the answer is in an
external file.
4 Make sure that when you create your C programs, your program includes the information header
comment block shown above including your name. Also make sure you include a comment to
describe your specific C program before main. Remove the unneeded default messages and put in
your own messages.
There is info at the above and at the bottom of this assignment about creating a folder for your
assignment files to be turned in and submitting the assignment.
Instructions that apply to all lab questions:
A. For later labs, if the instructions say to use code from previous lab/question then everything
from previous question should still be in lab except what is explicitly changed in the current question.
B. ** Things not allowed in Dr. Tiernan’s 1310 class in C programs. {More details about these
things will be posted in the file “Things Not Allowed”} If you use these elements in your lab assignment
C code, you will get a 0 (zero) for the entire question where you used this element.
1) Cannot use exit
2) Cannot use break except between case statements in a switch structure
3) Cannot use continue
4) Cannot use an intentional infinite loop such as while (true)
5) Cannot use goto
6) Cannot use global variables but global constants are allowed
Lab 4 Topics:
Multi-dimensional arrays, algorithms, formatting output, functions, file output, recursion
Grading Rubric for Lab 4:
Part 1: 27 points
1.a) 3 pts
1.b) 3 pts
1.c) 3 pts
1.d) 3 pts
1.e) 3 pts
1.f) 3 pts
1.g) 3 pts
1.h) 3 pts
1.i) 3 pts
Part 2: 28 points
2.a) 11 pts (see detailed rubric after question)
2.b) 17 pts
Part 3: 21 points
3.a) 12 pts
3.b) 9 pts
Part 4: 13 points
Part 5: 11 points
Optional Extra Credit Part 6: 12 points
Optional Extra Credit Part 7: 4 points
Miscellaneous: If you have questions, e-mail Dr. T and/or the TAs through Canvas.
Lab 4 parts to complete:
Part 1: Practicing with multi-dimensional arrays for storing data from file input, manipulating up
data, and printing data using loops. You will start Lab 4 with the code I give you for Lab 3 as well as a
new data file that includes data for robot height. The lab I am providing is DrTLab3.c .
The initial input data will come from a file called “robotInfoL4.txt”. This file has the following format
on each line: [Note that this is the same as Lab3 data with the addition of height information.]
word number word double character word multi-word-string
Ex. C3PO 1977 humanoid 5.75 M 11M Star Wars
The meanings of the each piece of data are as follows:
robotName robotYear robotKind robotHtFt robotSource robotCost robotSourceTitle
Ex. Opportunity 2004 aerospace 4.9 R 400M NASA
The constraints of new piece of data are as follows:
robotHtFt – a double that gives the height of the robot in feet. A valid height must be greater than 0.
1) For Lab 4 you will start with the Lab3 C file that I am providing for you called DrTLab3.c . Review the
code that is given and answer the following questions:
1.a) Why is the file ctype.h included as one of the header files? Why is it needed specifically?{3 pts}
1.b) What part of Lab3 does the function printBotSent implement? Describe in a phrase or sentence
and give reference to the specific Lab3 question that is answered with this function. {3 pts}
1.c) What does function prtSep do? Describe its actions in three sentences or less? {3 pts}
1.d) In function main near line 209, what does the statement below do? Describe its actions in three
sentences or less. {3 pts}
sprintf(tmpWd, "%.0lf", botInt[botCnt][CST]);
1.d) In function printBotSent near line 256, what does the code shown below do in the program?
Describe its actions in three sentences or less. {3 pts}
((botSrc[r] == 'R')? "In" : "The")
1.e) In function main, what can be stored in the array declared below? Describe this array IN YOUR
OWN words. {3 pts}
char botDataStr[BOTMAX][STRCOLMAX][STRMAX];
1.f) In the program, assume that you have a variable row with a value of 4 and the column value of
TITLE. Using the data file given with the program, what value would be stored at the location below
after all the data has been read in? {3 pts}
botDataStr[row][TITLE] would have the value _________________________
1.g) In the program, assume that you have a variable row with an unknown value and an unknown
column value. Using the data file given with the program, what values would need to be stored in the
row variable and what constant would be needed to access the value below? {3 pts}
11M would be in botDataStr[ row ][ ] where
row = ______________ and
The column constant would be _________________
1.h) In the function printBotTbl, what does the nested if else near line 294 do to change the output?
Describe its actions in three sentences or less. {3 pts}
Part 2: Manipulating multi-dimensional arrays for searching data. Continuing with the Lab 3 code I
have given you.
2) Create a new project XYZ1234Lab4Part2.c and copy all of DrTLab3.c into your new project. Update
the header info to include your name along with mine. This section of the lab will have you write a
couple of linear search functions to use with the multi-dimensional array.
Search algorithms are simply recipes for looking through a data structure, in this case an array, to try to
find a particular element. When we look for a maximum or a minimum value, we are doing specialized
search functions. For this question you are going to implement two search functions to look for values
in the string 2D array (botDataStr – also considered a 3d character array) and another value in the int
2D array (botInt).
2.a) In the numeric array, you are going to search for a value in one of the columns. You will be given
a value to search for, a column number to search in, and the number of robots in the array. You will be
asking the user for two pieces of data (value and column) and then using a function to determine
either the first location of the given value or that the value is not in the array in the given column.
Create a function called arr2Dsearch. The function should take in the integer 2D array, a value to
search for (for example target), a number indicating which column to search in (e.g. col), and a count of
the number of meaningful rows in the array (e.g. count). The function should return a row value. This
function will implement a linear search.
In the function, declare an integer variable to hold the location of the found value (ex. found). Set this
variable to negative one (-1) initially. Remember that a value of 0 would indicate row 0 in the array
which would be valid.
Create a definite loop to loop for the number of meaningful rows in the array, i.e. the number of
robots in the array. [This is the number of rows that actually have data in them as opposed to all the
rows in the array.]. Inside the loop, compare the value in the current row at the given column (col)
against the value to search for (target). If the current value equals the target, then set found to the
current row value and return found. If the loop ends without finding target, then return the original
value of found, i.e. -1.
In the main routine, ask the user if they want to search the year, the numeric cost, or the height. Save
this info to determine which column to search. Then ask the user to enter a value to search for. This
will be the search target.
With this user input and still in the main routine, call this int search function using the numeric array,
the target number from the user, and the column to search, and then save the location that is returned
from the function. If the function returns -1, then print a message indicating that the target value was
not found in the array. If the function returns a non-negative value, then print a message indicating
that the target value was found in the array at row X in the column they selected (year, cost, or height),
where X is the location value that is returned from the function. Don't forget to put the first line of the
function up top as a function prototype.
When you have completed these changes, your code should work properly and print a message about
whether the input value was found.
When your code works, take one or more screenshots of your output. Remember that all your answers
and screenshots go in your answers document for Lab4. You should also now have your working
version of XYZ1234Lab4Part2a.c . You will need to SAVE a COPY of this program in your Lab4 folder.
Rubric: {11 pts}
Q 2.a will be graded by looking at your XYZ1234Lab4Part2a.c and your screenshots.
Correct function header with correct parameters, return type, and prototype declaration {2 pts}
Correct implementation of loop to iterate through array {1 pts}
Correct search algorithm coded in function with correct action if found {2 pts} and if not found {1 pts}
Correct value returned from function to main {1 pt}
Correct user input in main for search target and column to search (year, numeric cost, height) {2 pts}
Correct function call in main {1 pts}
Correct behavior (output) if search target is found in the array {2 pts}
Correct behavior if search target is ultimately NOT found in the array {1 pts}
2.b) In the string array, you are going to search for a value in either the source word or the kind
column. The user will be asked to enter an source word (or phrase), in all lowercase, or to enter a kind,
capitalized. Based on whether the word is capitalized or not, your program should determine which
column to search using the given word for the search target. This function will implement a linear
search.
You should write this search as a function named findSrcKnd. The findSrcKnd function should take in
the three dimensional string array, the number of robots in the string array, and an empty int array
named srcKndLoc with two elements as input and return a void value. The actual results from the
function will be stored in the srcKndLoc int array with the found robot row value in element [0] and the
source or kind column value in element [1]. Inside the function, initially set both array values to -1.
Inside the function, ask the user to enter a string to search for, a target string. The string could be more
than one word. Tell them to use all lowercase letters for a source word and to capitalize a kind. Print
out a message that verifies the string entered by the user.
Use the user input string to determine whether to search in source word or kind. You can test this in a
variety of ways so choose one of these or implement your own test. Here are some ways you could
check this: [You may choose any of these methods or make your own]
A) Copy the string into a temporary string. Use the tolower character function to change the first
letter of the temp string to a lowercase letter. Compare the original word and the copy. If they are
the same, search the source word, else search in the kind.
B) If the first letter of the word is equal to or greater than 'A' and also less than or equal to 'Z', then
search in the kind, else search in the source word.
C) If the first letter of the word is lowercase as indicated by the islower character function, then
search in the source word, else search in the kind.
For any of these methods if you are searching the source, then set your search column value equal to
the source array location (SWORD). Likewise, if you are searching the kind, then set your search
column value equal to the kind array location (KIND).
Now create one loop that iterates for the number of robots in the array. (This value is passed in.)
Inside this loop, compare the user's input string to the current string in the selected search column. If
the values are the same and the int array still has -1 in it at [0], then save the current index of the array
in the int array at [0] and the selected search column value at [1]. When all elements in the robot array
have been compared, return from the function back to main.
In the main, declare array srcKndLoc . Then call findSrcKnd passing in the multidimensional string
array, the number of robots stored in the array, and the two element int array srcKndLoc. After the
function call in the main routine, print a message like:
String target is found in the string array at location [X][Y]. // OR
The “target” was found in row X in column Y. // or print a word for Y
where X is the robot row number (found in the srcKndLoc array location [0]), Y is the search column
number for source or kind (found in the srcKndLoc array location [1]), and target is the value found at
location [X][Y] in the string array. However, if srcKndLoc[0] equals -1, then no matching value was
found so print the message:
target was not be found in the string array
Where target is the value input from the user.
When your code works, take one or more screenshots of your output. Remember that all your answers
and screenshots go in your answers document for Lab4. You should also now have your working
version of XYZ1234Lab4Part2b.c . You will need to SAVE a COPY of this program in your Lab4 folder.
Rubric: {17 pts}
Q 2.b will be graded by looking at your XYZ1234Lab4Part2b.c and your screenshots.
Correct function header with correct parameters, return type, and prototype declaration {2 pts}
Correct user input for source word or kind string {2 pts}
Correct determination of source vs. kind {3 pts}
Correct implementation of loop to iterate through array and correct string comparison {2 pts}
Correct saving of string array location into array srcKndLoc {2 pts}
Correct search algorithm coded in function with correct action if found {1 pts}
Correct value returned from function to main in array srcKndLoc {2 pt}
Correct function call in main {1 pts}
Correct output if search target is found in the array and if ultimately NOT found in the array {2 pts}
3) Create a new project XYZ1234Lab4Part3a.c and copy all of XYZ1234Lab4Part2b.c into your new
project. In this section of the lab you will do two Bubble Sorts of one dimensional arrays that are
copied from the multi-dimensional arrays. You will first bubble sort an integer array, then in a new
function sort a string array.
3.a) Create a bubble sort function named bubbleSort1DNum. The bubble sort function should take in
the 2D number array, the number of robots, i.e. the number of meaningful elements in the arrays, and
the index of which column to sort from the number array. This will allow this function to sort on either
the year, the numeric cost, or the height. For this sort, only the one type of value selected (year, cost,
or height) will be sorted.
In the bubble sort function, the general algorithm for bubble sort is as follows:
A. begin bubbleSort(arrays, count, sort_column). // you may use any meaningful names you choose
A.a. Copy selected sort_column data into a temporary array to sort
B. for all elements of array that is to be sorted
C. if array[i] > array[i+1]
D. swap array locations (array[i], array[i+1])
E. end if
end for
F. verify sort if needed
return array // in C this step is already done
end BubbleSort
The next sections discuss the A. – F. lines above.
A. Declare the function header for the bubble sort function with the input parameters as described
above. The return type can be void or int if desired. Make sure to copy the function header to the top
of the program as the function prototype.
A.a. Inside the bubble sort, declare a temporary array and copy all the selected array values
into the temporary array. This means that if the cost value is being sorted, the copy all the
costs from the COST column in the input array into the temporary array.
B. Create a loop in the body of the function. The loop should iterate from 0 to the number of
elements in the array. Set up the body of the loop.
C. In the loop body, create an if statement that compares the value in the temporary array at the
current row against the value in the next row. If the current value is larger than the next value, then
the values need to be swapped.
D. This is the heart of the sort function. To swap two array elements you will follow the basic
algorithm of :
temp_element = array[current_row]
array[current_row] = array[current_row + 1]
array[current_row + 1] = temp_element
This is the process to use for the temporary array.
E. End the if condition and then end the loop.
F. For function bubbleSort1DNum, verify that the temporary array was correctly sorted by printing the
array values in a column with the index values printed. Your output could look like :
Sorted data from column 1 in numeric array OR
Sorted values from column COST
0] 5000
1] 28000
2] 74000
OR
Sorted data from column 0 in numeric array OR
Sorted values from column YEAR
0] 1939
1] 1948
2] 1952
or something similar. Be sure to include a title line above the sorted values describing what is being
printed. After the temporary array is printed, have the return statement and then end the function.
Be sure to put the function header for bubbleSort1DNum above the main.
In the main routine, after printing the sentences (printBotSent) and the final table (printBotTbl), add a
call to the function bubbleSort1DNum. Run and test your program.
When your code works, take one or more screenshots of the output with the sorted array added. Also,
save a copy of XYZ1234Lab4Part3a.c in your Lab4 folder. Be sure to indicate in your answers document
that the grader should reference the named .c file.
Rubric: {12 pts}
Q 3a will be graded by looking at your XYZ1234Lab4Part3a.c and your screenshots.
Correct function header for bubbleSortInt1DNum with correct parameters, return type, and prototype
declaration {2 pts}
Correct function loop for going through the array {2 pts}
Correct comparison in loop for looking at order of elements {2 pts}
Correct swap steps to swap all array values {4 pts}
Correct output of sorted number array {2 pts}
3.b) Create a new project XYZ1234Lab4Part3b.c and copy all of XYZ1234Lab4Part3a.c into your new
project. Create a bubble sort function named bubbleSort1DStr. The bubble sort function should take
in the 2D string array (the 3D array of char), the number of robots, i.e. the number of meaningful
elements in the arrays, and the index of which column to sort from the string array. This will allow this
function to sort on either the name, kind, cost string, title, or source word. For this sort, only the one
type of value selected (name, kind, cost, title, sword) will be sorted.
This new bubbleSort function has the same algorithm as the bubble sort for numbers. You will need to
create a temporary array of strings and copy the values from the selected column in the string array
into the temporary array.
The other main differences in the bubble sort are in the comparison (step C), the swap action (step D),
and the verification (step F). In step C, the comparison of strings must be done with strcmp rather than
with the arithmetic comparison operators. In step D, the swap steps require strcpy instead of just the
assignment statement. In step F, print the temporary array of string values with an appropriate title.
The remaining steps are the same.
Be sure to put the function header for bubbleSort1DStr above the main.
In the main routine, after the call to the function bubbleSort1DNum, put a call to the function
bubbleSort1DStr . Run and test your program.
When your code works, take one or more screenshots of the output with the sorted string array added.
Also, save a copy of XYZ1234Lab4Part3b.c in your Lab4 folder. Be sure to indicate in your answers
document that the grader should reference the named .c file.
Rubric: {9 pts}
Q 3b will be graded by looking at your XYZ1234Lab4Part3b.c and your screenshots.
Correct function header for bubbleSortInt1DStr with correct parameters, return type, and prototype
declaration {2 pts}
Correct function loop for going through the array {1 pts}
Correct comparison in loop for looking at order of elements {2 pts}
Correct swap steps to swap all array values {2 pts}
Correct output of sorted string array {2 pts}
4) In this part of the program you will again use a bubble sort function and you will again be sorting the
multi-dimensional numeric array. However, this time you will be sorting the original array and then
keeping all the other arrays in order along with the one being sorted. This means that if you sort the
numeric array such that the costs are ordered from smallest to largest (like the example given earlier)
that you will also be sorting the strings array so that the associated string and char arrays are also
sorted in order with them. This would mean that part of your output data would contain, as partial
examples,
Array data sorted by column 1 in numeric array OR
Array data sorted by column COST
0] 5000 Marvin the Paranoid Android B
1] 28000 Elsie R
2] 74000 Spot R
The instructions below will indicate how you should print your output after sorting.
Create a new project XYZ1234Lab4Part4.c and copy all of XYZ1234Lab4Part3b.c into your new project.
Create a bubble sort function named bubbleSort2DNum. The bubble sort function should take in all
three of the data arrays (numbers, strings, char), the number of robots, i.e. the number of meaningful
elements in the arrays, and a value indicating which column in the numeric array to sort on. This will
allow this function to sort on either the year, the numeric cost, or the height. In each of these cases,
the function will make sure that all three of the arrays will stay in alignment with the newly sorted
integer array.
This new bubbleSort function has the same algorithm as the bubble sort for numbers except that you
will not use step A.a. You will be sorting the arrays that are passed in rather than making a copy as
before.
The step C comparison will be the same test as before except testing the elements in the original array.
The pseudocode will be :
C. if array[i][sort_column] > array[i+1][sort_column]
The step D swap will have the biggest change. In step D your program will need to swap all of the
arrays
D. swap all arrays (array[i], array[i+1])
For a one dimensional array such as the source letter array, In order to swap two array elements you
will follow the same basic algorithm as used for the temporary array :
temp_element = array[current_row]
array[current_row] = array[current_row + 1]
array[current_row + 1] = temp_element
For arrays with multiple columns, add a loop to go through the columns in the multi-dimensional
arrays. This just means to use pseudocode like:
for (increment col from 0 to number_of_robots)
{
temp_element = array[current_row][col]
array[current_row][col] = array[current_row + 1][col]
array[current_row + 1][col] = temp_element
}
Remember that each type of array has a different number of columns so each array needs its own
loop.
For this question you will not need to do a verification step F inside the bubble sort function. The
remaining steps are the same.
Be sure to put the function header for bubbleSort2DNum above the main.
In the main routine, after the call to the function bubbleSort1DStr, put a call to the function
bubbleSort2DNum. In main after the call to bubbleSort2DNum, print a title like “Array data sorted by
COST” (or whichever column is appropriate) and then call the function printBotTbl to print the newly
sorted set of data. Run and test your program.
When your code works, take one or more screenshots of the output with the sorted array added. Also,
save a copy of XYZ1234Lab4Part4.c in your Lab4 folder. Be sure to indicate in your answers document
that the grader should reference the named .c file.
Rubric: {13 pts} Q 4 will be graded by looking at your XYZ1234Lab4Part4.c and your screenshots.
Correct function header with correct parameters, return type, and prototype declaration {2 pts}
Correct function loop for going through the array {1 pts}
Correct comparison in loop for looking at order of elements using input column {2 pts}
Correct swap steps to swap all arrays {4 pts}
Correct function call in main function {2 pt}
Correct sorted table printed in main after function call to bubblesort {2 pt}
5) Create a new project XYZ1234Lab4Part5.c and copy all of XYZ1234Lab4Part4.c into your new
project. In this section of the lab you will be binary searching the numeric array by reading target
values from a file. You will write a new function to implement binary search on the sorted numeric
array using the year. You will have a model of the binary search to use that we will do in class.
Write your binary search function to take in the numeric array, the starting index of the array, the
ending index of the array, and the target year value to search for. When binary search is first called the
starting index is 0 and the ending index is the count of meaningful values minus one.
In the binary search function, the general algorithm for binary search is as follows:
(Prep) Make sure the array is sorted (this can be before the search is called)
A. Start a loop that runs as long as the starting index is less than or equal to the ending index.
B. Given a start and end index, find the middle index by averaging them.
C. Compare the value at the middle index to the target,
If the match, return the middle index.
D. Else if the value at the middle index is greater than the target,
Then change the ending index to the middle index - 1.
E. Else // the value at the middle index is less than the target
Then change the starting index to the middle index + 1.
End loop
F. After the loop, if the function did not return when it found a value in step B,
then return -1 to indicate that the target was not found
Create a data file, named XYZ1234Part5Data.txt, that should have at least 5 different search target
year values, including at least one value that is outside the valid range of years and one value that is a
string but not a number. In the main function, sort the arrays based on year and then create a loop
that will read a value from the file, print the search target that you read in, then do the binary search.
If the binary search find the value, it should return the row of the value. If the search doesn't find the
value, it returns -1. Print a message in a sentence that indicates whether the year search target was
found and where. Then go back to the top of the loop and read the next search target from the file.
Continue to read and search until you have read all the search target values from the file.
When your code works, take one or more screenshots of your output. Take screenshots of the binary
search results. Remember that all your answers and screenshots go in your answers document for
Lab4. You should also now have your working version of XYZ1234Lab4Part5.c and you will have a data
file XYZ1234Part5Data.txt. You will need to SAVE a COPY of this program and this data file in your Lab4
folder.
Rubric: {11 pts} Q 5 will be graded by looking at your XYZ1234Lab4Part5.c, your data file, and your
screenshots.
Correct binary search function implemented {5 pts}
Valid data file that meets all requirements {3 pts}
Correct output produced for all file values {3 pts}
[NOT REQUIRED FOR THE LAB. THIS IS OPTIONAL]
Extra Credit 6) Create a new project XYZ1234Lab4Part6.c and copy all of XYZ1234Lab4Part5.c into your
new project. Implement a new binary search in a recursive function. Write this second binary search
function that is recursive and searches the height number column in the array. Create an input file,
XYZ1234Part6Data.txt, with at least 5 different search target height values including at least one
invalid value. In the main function, sort the arrays on the height column. Then, in a loop, read a value
from the file, print the search target that you read in, then do the binary search. If you find the value,
the search will return the row of the value. If you don't find the value, the search returns -1. Print a
message that indicates whether the issue number search target was found and where. Then go back
to the top and read the next search target from the file. Continue to read and search until you have
read all the search target values from the file.
Write your recursive binary search function to take in the numeric array, the starting index of the
array, the ending index of the array, and the target year value to search for. When recursive binary
search is first called the starting index is 0 and the ending index is the count of meaningful values
minus one.
In the binary search function, the general algorithm for binary search is as follows:
(Prep) Make sure the array is sorted (this can be before the search is called)
A. If the starting index is greater than the ending index
Return -1
B. Given the start and end index, find the middle index by averaging them.
C. Compare the value at the middle index to the target,
If they match, return the middle index.
D. Else if the value at the middle index is greater than the target,
Then call the recursive binary search again with the same starting index and change the ending
index to the middle index - 1.
E. Else // the value at the middle index is less than the target
Then call the recursive binary search again, change the starting index to the middle index + 1
and keep the same ending index .
Run and test your code.
When your code works, take one or more screenshots of your output. Take screenshots of the binary
search results. Remember that all your answers and screenshots go in your answers document for
Lab4. You should also now have your working version of XYZ1234Lab4Part6.c and you will have a data
file XYZ1234Part6Data.txt You will need to SAVE a COPY of this program in your Lab4 folder.
Rubric: {12 pts} Q 6 will be graded by looking at your XYZ1234Lab4Part6.c and your screenshots.
Correct recursive version of binary search function implemented {8 pts}
Correct output produced for all file values {4 pts}
[NOT REQUIRED FOR THE LAB. THIS IS OPTIONAL]
Extra Credit 7) Continuing with XYZ1234Lab4Part6.c, in part 3.a.F or part 4, in the output “found
target” messages, instead of printing a column number for the numeric array, print a word indicating
the meaning of the column. This could be done in many ways such as using some ternary operators or
a small function that takes in the column number in a specific array and returns a word string. For
example, for the numeric array, for column 0, the word “year” or “YEAR” could be printed, for column
1, “cost” or “AMOUNT” or something similar, and for column 2, “height”, “Ht in ft”, “HEIGHT”, etc.
Modify your output statements that included column numbers in the numeric array to print out these
associate words instead of the column numbers.
Note that if you did this earlier in the code already, this section can highlight that code and would not
require additional code to be written.
When your code works, take one or more screenshots of your output showing this word
implementation. Remember that all your answers and screenshots go in your answers document for
Lab4. You should also now have your working version of XYZ1234Lab4Part7.c OR you can indicate
where this functionality already exists in the Part 5 or Part 6 code. If you wrote new code for Part 7
you will need to SAVE a COPY of this program in your Lab4 folder
Rubric: {4 pts} Q 7 will be graded by looking at your code and your screenshots.
Modification of code to print a word instead of a number. {4 pts}
--------------------------------------------------------------------------------------------------------
Important suggestions to help you be successful
A. Pay close attention to all requirements on this page, including file names and submission format.
Even in cases where the program works correctly, points will be taken off for not following the
instructions given on this page (such as wrong file names, wrong compression format for the
submitted code, and so on). The reason is that non-compliance with the instructions makes the
grading process significantly (and unnecessarily) more time consuming. Contact the instructor or TA
if you have any questions.
B. For each new question that requires you to write code, make a new C project with the exact name
that you need to use. Double check that there are no errors before submission. In case of an error
in this situation, 0 points will be awarded.
C. Write your code in small steps. Do NOT try to write 25 lines of code and then start trying to run it.
Instead, write a small chunk of code - 5 to 10 lines - then save and run those 10 lines to make sure
they work and then continue. If the 5 to 10 lines have any errors, start on the errors closest to the
top of the file and fix those first. Once you have made changes to fix ONE error, then run the code
again to see if that really did fix the error. Don’t go forward until you have fixed to topmost error.
If you can’t figure out how to fix that one – try to comment out the line with the error and then fix
the remaining errors in your chunk. Don’t go further until you have fixed what you have so far.
D. If you are working on a project and want to start completely over (which is not always the best
idea), copy the “old code” that you do not plan to reuse and save it into a text file in a directory
with your other materials for the class. You may discover that you do want to reuse that code and
if you have saved it, then you won’t have to rewrite all of it.
Instructions for preparing your lab to turn in:
How to prepare your assignment to turn in (or to "submit")
If you have not already done this, then create a folder for your lab in your CSE 1310 class directory on
YOUR computer and name the lab folder with your initials, your last 4 digits, and LabX. [If you don’t
have your files organized into folders, I STRONGLY suggest that you start doing this. This is a way to
sort the material you keep on your computer and be able to find it later. Check the internet for
suggestions on how to do this type of organization.)
As an example, if your name is Happy Camper 1010101010, then your Lab 1 folder name is
HXC1010Lab v Save your HXC1010Lab1answers file in this folder. Next save all the .c files from
OnlineGDB for the assignment in the folder. Below is how to do that. Once you have put all the
needed .c files in your folder, zip the folder to compress it before submitting it (see info further down
with submission details).
Saving .c files out of OnlineGDB [There are two different ways to save the .c files]
First method – downloading the files one by one from OnlineGDB (Great for few or single files)
Go to the Project (the program) in OnlineGDB that you want to save and open it. Make sure the
program is open in the main window and is the program you are looking at. For example, if you are
saving the main.c file for Lab1Part5 you will see the main.c file will say Lab1Part5 in the comments.
Make sure your cursor clicks in the editing window of that file. Along the top of the editing window
you will see a light blue download arrow. Click the arrow to download just the code in the window you
are looking at. For programs that only have one main.c file (and no other text files) this method works
fine. Save the .c file into the folder that you plan to submit and name the .c file to the appropriate
name for the lab part you are working on. Don't forget to save the .c file in OnlineGDB into your My
Projects directory so you can reuse it later if needed.
Second method – downloading the Project file and then unzipping the files from the project folder
To download your entire project folder of C code from OnlineGDB you should go to My Projects and
then, for the project you need to download, use the download button under the Actions label. When
you click the button, you'll get a typical download window. Save the .zip file that is downloaded into
the folder that you plan to submit and name the project folder something useful so you remember
what it is. Once the file is downloaded, it will be a zipped (compressed) file like LabX.zip . Once it is in
your directory, click on it and UNZIP the file contents. You may need to select how to uncompress the
files from the .zip archive. After you unzip the file, you should see the .zip file and the contents that
have been uncompressed. You need to keep the .c files that are unzipped (and any text files that might
have been created or used) and you need to delete the zip file that was downloaded from OnlineGDB.
Rename the main.c file to the appropriate name for the lab part you are working on and then delete
the .zip file. Naming NOTE: Because C names all of the main files as main.c, you will need to save each
unique main.c so that it is renamed to the correct filename and then save these .c files into your
XYZ1234Lab1 folder for submission. Thus, if you are turning in Lab 1 with three parts, then you should
end up with three .c files named XYZ1234Lab1Part1.c , XYZ1234Lab1Part2.c , and XYZ1234Lab1Part3.c
where each of these files contains the main function for that particular program. { 5 point deduction
for saving main.c instead of appropriately named .c files}
Reopening projects: If you have closed a project in OnlineGDB and want to go back to it to edit it some
more, you can go to the project by going to the My Projects link on the left menu of the window. Then
select the folder of the project you want. Open the folder and then select the name of the main.c or
other source file you want, then click on the that file. This will open the program again in the editing
window for you to keep working on.
C FILE NOTE: Only the .c files and the answers file should be included in your zipped folder. Do NOT
include the entire OnlineGDB project. You will be penalized if you save the project instead of just the .c
file. { 5 point deduction for saving whole projects instead of just .c files}
How to submit
The assignment should be submitted via Canvas. Submit a ZIPPED directory/folder called
XYZ1234Lab1.zip. The folder must be ZIPped (not RAR). No other forms of compression accepted.
(Contact the instructor or TA if you do not know how to produce .zip files). The zipped directory should
contain your answers document and all the C code files (task1.c etc).
To create a zipped directory called XYZ1234Lab1.zip, follow these steps:
1. Create a folder called XYZ1234Lab1. {This should be the same folder you created already that
has your files in it.)
2. If not already done, copy to that folder all your solutions (your answers file, all your C files, and
any .txt files that were required for input or output). NOTE: Be sure to save the original document in
your folder. Don't save just a link to the file. You can check to make sure you have saved the actual
document by checking the size of the file you saved. If the file is too small, you may have only a link
and not the file itself.
3. Zip that folder.
• On some Windows systems, you can zip a folder by right-clicking on the folder, and then
selecting Send to->Compressed (zipped) folder.
• On Mac, go to the parent directory of your Lab# directory in a Finder window, click on your
XYZ1234Lab# folder, then select Compress from the list of file actions (under the gear icon).
4. Submit your zipped folder through your Canvas account at the lab assignment. You click on the
name of the assignment and then it goes to the screen where you can upload your zipped file.
(Assignments are only accepted through Canvas.)
5. Check that what you uploaded is exactly what you want by going into Canvas and then
downloading the assignment you just uploaded, unzipping the folder, and checking the contents to
make sure that everything you want to be there is present. NOTE: Related to saving a file versus a link
– try downloading your lab onto a different computer. If you saved the correct file, then this will
download correctly on the other computer. However, if you saved only the link, then the file will not
download onto the other computer.
Submission checklist
• Did you correctly name all the lab submission elements – answer document, .c files, the folder, etc?
• Did you create one answers file with your name and UTA ID in the file, and did you include all your
answers to non-programming tasks and references to the code files as needed?
• Did you include all the needed screenshots for output making sure that each screenshot was large
enough to be read but small enough to keep the answers document from becoming huge?
• Did you answer all of the questions in the lab assignment and did you create all the required .c
program files and text files, if any?
• Do all your .c program files run without errors in OnlineGDB?
• Do all your .c program files run and give correct answers in OnlineGDB?
• Did you put all of the files you created into one folder called XYZ1234Lab# ?
• Did you zip that folder into a file called XYZ1234Lab#.zip?
• Did you upload the zipped file to Canvas before the due date and time?
• Did you check what you uploaded to Canvas to make sure it has the desired material in it?
CSE 1310 – Fall 22
Introduction to Programming
Lab 4
Deadline:
This Lab has a firm deadline. There will be no late extensions.
Purpose:
Grading
Instructions for naming the folders and files that you create for this lab assignment:
Instructions about the folder that will contain the files required for the Lab:
Instructions about the Answers document required for the Lab:
Instructions about C files, i.e. the .c documents:
C file header blocks
Instructions about data files, i.e. the .txt documents:
Summary of answer document and .c files prep
There is info at the above and at the bottom of this assignment about creating a folder for your assignment files to be turned in and submitting the assignment.
Instructions that apply to all lab questions:
Instructions for preparing your lab to turn in:
How to prepare your assignment to turn in (or to "submit")
Saving .c files out of OnlineGDB [There are two different ways to save the .c files]
Explanations and Answers
0
No answers posted
Post your Answer - free or at a fee
NB: Post a homework question for free and get answers - free or paid homework help.
Get answers to: Multi-Dimensional Arrays, Algorithm, And Recursion. or similar questions only at Tutlance.
Related Questions
- Need Statistical Analysis Conducted To Demonstrate 95% Ci For Pharmaceutical Application.
- Need Statistical Analysis Conducted To Demonstrate 95% Ci For Pharmaceutical Application.
- Need Statistical Analysis Conducted To Demonstrate 95% Ci For Pharmaceutical Application.
- Need Statistical Analysis Conducted To Demonstrate 95% Ci For Pharmaceutical Application.
- Dungeons And Dragons Game Replication In C++
- Horoscope Project Help Complete C++
- Horoscope Project C++ Can I Get Someone To Complete It
- Does A Program Of Purposeful Rounding Improve Employee Engagement And Reduce Serious Safety Events?
- Does A Program Of Purposeful Rounding Improve Employee Engagement And Reduce Serious Safety Events?
- 4Th Order Runge-Kutta Method With Matlab
- 4Th Order Runge-Kutta Method With Matlab
- Facebook Webscrapped Data From A Private Page
- Sas Coding And Analysis Project
- Sas Coding And Analysis Project
- Sas Coding And Analysis Project
- My Question Is About A C++ Program
- Creating A Small Village In Pygame And Pyopengl
- Multi Threaded Java Client Server Chat App Which Follows Specific Json Protocols
- Medical Image Segmentation By Pytorch
- Use The Bash Shell And Develop A Shell Scripting
- Matlab Programming Project!!!!
- Programming 1 C++ Final Project
- Machine-Level Representation Of Programs
- Increasing Rectangle Width According To Slider Value In Javafx And Scenebuilder
- Data Science Assignments & Matplotlib
- Develop A Graphical User Interface Implemented In Matlab App Designer To Manipulate And Plot Circles
- Mbtn Academy Marketing Analyis
- Mbtn Academy Marketing Analyis
- Practice Final Exam And Final Exam
- C++ Programing 1 Project Homework 6
- 2 Matlab Intergration Questions
- Technical Skills Are All That Is Necessary To Be Successful Engineer. Discuss
- C++ Adding/Completing Class And Member Function Definitions
- Technical Skills Are All That Is Necessary To Be Successful Engineer. Discuss
- C++ - Adding/Completing Class And Member Function Definitions
- Sas Homework ( Requires Showing The Codes And Commenting)
- Need To Build A Fullstack With Python, Flask, Bcryp, Flash, Session, Request, Mysql, Pymysql, Mysql Workbench
- C++ Programming Project- Spell Checker Program
- Sas Programmer In Economics Class
- C++ Programing Homework Assignment
- Insurance Adjuster Final Exam That Is Time It’s 150 Questions And 180 Minutes To Complete.
- Assembly Language Using Pep 8 : Code Transpose Of Myszkowski
- . Is Public Transit Accessible To Lihct Units? Do Lihct Developments Have Feasible Acces To Coast Rta Bus Systems?
- C++ Programming Project- Spell Checker Program
- C++ Phonebook Lab- Linked List
- Domain Modeling And Class Diagrams
- Software Architecture Diagram
- Software Architecture Diagram
- Implementing Sequence Diagrams
- Implementing Object Model Assignment