Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include <stdio.h> #include <stdlib.h> #include <time.h> #include <string.h> /**

ID: 3706510 • Letter: #

Question

#include <stdio.h>

#include <stdlib.h>

#include <time.h>

#include <string.h>

/******************************************************************************

* Print out a header - should contain your name, netid, lab time, and a

* brief description of the program (5 points, 2 points done by autograder,

* 3 points done by grader)

* Comments - include block comments to describe your code (5 points,

* done by grader)

* Write a program that will populate a 2-d array of c-strings that will

* be used for a classroom seating chart, print out

* all the strings entered in a table, and then calculate

* some values on the 2-d array of c-strings.

*

* Your main should read in the number of rows first and then columns

* that are in the seating chart. (10 points done by autograder)

* The code should make sure that the number of rows or number of

* columns requested is not larger than the 10x10 array and loop until

* values less than 10 are entered (10 points done by autograder). You should have code in

* the main of your program that calls and display any results from the

* three functions in an appropriate manner. (10 points done by grader)

*

* The 2d array and any other information MUST be passed to the functions.

* No global variables should be used.

*

* The first function readNames will populate the 2d array with C-strings.

* The function will have arguments for the number of

* rows and number of columns in the 2d grid. The function will then read

* the strings (including whitespace) storing them in columns first. (20 points)

*

* The next function, printChart, prints the 2d array of c-strings nicely as a

* table, making sure columns line up. Each row on the screen should correspond

* to each row in the seating chart. (20 points). (15 points autograded,

* 5 points done by grader to make sure nicely formatted in columns)

*

* The third function will described on the board during your assigned

* lab time. (20 points autograded).

functions 3 part 1:

where name[length] is uppercase

functions 3 Part 2:

average over columns

*/

void readNames(char myChart[10][10][15], int numRows, int numCols)

{

// place code for readNames here

}

void printChart(char myChart[10][10][15], int numRows, int numCols)

{

// place code for printChart here

}

/******************************************************************************

* Third Function

* your function should return the number of names in the entire chart

* _________{PART 1} _______ (10 points)

* AND create a 1-d array that

* holds the average length of the names per ___{PART 2} ____ (a 1-d array of

* doubles) (10 points).

* length will be provided by the user and should be requested to be entered

* in main and passed to the function. The results from the function should

* then be displayed by main

***************************************************************************/

int thirdFunction(char myChart[10][10][15], int numRows, int numCols, int length, double values[10])

{

// place code for third function here, description for PART1

// and PART 2 above will be

// posted on the board during your assigned lab period

}

int main() {

char ourRoom[10][10][15]; // largest chart we will need

double results[10]; // for thirdFunction results

// place code here for your header

// place code here for reading in number rows, number columns, and

// code that makes sure the rows and columns are always less than 10 and

// also code that calls your three functions appropriately

return 0;

}

Explanation / Answer

Below is your code: -

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
/******************************************************************************


* Comments - include block comments to describe your code (5 points,
* done by grader)
* Write a program that will populate a 2-d array of c-strings that will
* be used for a classroom seating chart, print out
* all the strings entered in a table, and then calculate
* some values on the 2-d array of c-strings.
*
* Your main should read in the number of rows first and then columns
* that are in the seating chart. (10 points done by autograder)
* The code should make sure that the number of rows or number of
* columns requested is not larger than the 10x10 array and loop until
* values less than 10 are entered (10 points done by autograder). You should
have code in
* the main of your program that calls and display any results from the
* three functions in an appropriate manner. (10 points done by grader)
*
* The 2d array and any other information MUST be passed to the functions.
* No global variables should be used.
*
* The first function readNames will populate the 2d array with C-strings.
* The function will have arguments for the number of
* rows and number of columns in the 2d grid. The function will then read
* the strings (including whitespace) storing them in columns first. (20 points)
*
* The next function, printChart, prints the 2d array of c-strings nicely as a
* table, making sure columns line up. Each row on the screen should correspond
* to each row in the seating chart. (20 points). (15 points autograded,
* 5 points done by grader to make sure nicely formatted in columns)
*
*
*
*/


void readNames(char myChart[10][10][15], int numRows, int numCols) {
// place code for readNames here
int i,j;
printf(" Please enter the values in mychart one by one ");
fflush(stdin);//clear buffer for scanf("%[^ ]s") to work properly
for(i=0;i<numRows;i++)
{
for(j=0;j<numCols;j++)
{
scanf("%[^ ]s",myChart[i][j]);//take input until user enters
fflush(stdin);
}
}
}


void printChart(char myChart[10][10][15], int numRows, int numCols) {
int i,j;
printf(" ### ");
for(i=0;i<numCols;i++)
{
printf("%d ",i+1);//printf column values
}printf(" ");
for(i=0;i<numRows;i++)
{
printf("%d ",i+1);//printf rows values
for(j=0;j<numCols;j++)
{
printf("%s ",myChart[i][j]);

}
printf(" ");
}
}


/******************************************************************************
* Third Function
* your function should return the number of names in the entire chart
* _________{PART 1} _______ (10 points)
* AND create a 1-d array that
* holds the average length of the names per ___{PART 2} ____ (a 1-d array of
* doubles) (10 points).
* length will be provided by the user and should be requested to be entered
* in main and passed to the function. The results from the function should
* then be displayed by main
***************************************************************************/
int thirdFunction(char myChart[10][10][15], int numRows, int numCols, int length, double values[10])
{
int track=0,index=0,sum=0,i,j;
for(i=0;i<numRows;i++)
{
for(j=0;j<numCols;j++)
{
if(track==length)//if track length is equal to length then reset it to zero for next iteration
{
values[index]=(sum*1.0)/length;//assign the average length to values array
index++;//increase the index value by 1 for next assignment of values array
sum=0;//reset sum to zero
track=0;//reset track to zero
}
sum+=strlen(myChart[i][j]);
track++;
}
}
values[index]=(sum*1.0)/length;//assign the last average value because control will come out of the loop without assigning the last value as no more elements left to traverse
return (numRows *numCols);//return number of names in the chart
}


int main() {
int again=1,row,column,length,i,length_Result;
char ourRoom[10][10][15]; // largest chart we will need
double results[10]; // for thirdFunction results

// place code here for your header
printf("Name - xyz ");//write your name here
printf("netid - xyz ");//write netid here
printf("lab time - xyz ");//write lab time here
printf("Description of the program - This program takes the room chart from user and shows the average length of the names per length(provided by user) ");
// place code here for reading in number rows, number columns, and
// code that makes sure the rows and columns are always less than 10 and
// also code that calls your three functions appropriately
do{
//take input for rows and column
printf(" Please enter number of rows : ");
scanf("%d",&row);
printf("Please enter number of columns : ");
scanf("%d",&column);
//if both are less than zero then only process the values
if(row<10 && column<10)
{
//call readnames
readNames(ourRoom,row,column);
//take length from user
printf("Please enter the length : ");
scanf("%d",&length);
//print the chart by calling printchart()
printf(" Chart is : ");
printChart(ourRoom,row,column);
//call thirdfunction()
int x=thirdFunction(ourRoom,row,column,length,results);
printf("The Number of names in the chart is : %d",x);
//if number of names is divisible by length then find the size of results array by dividing "no of elements"/"length"
if(x%length==0)
length_Result=x/length;
else length_Result=(x/length)+1;//if it is not divisible then increase one to store the remaining values average
  
//print the result calculated by thirdfunction
printf(" The Average length of the names per length=%d ",length);
for(i=0;i<length_Result;i++)
{
printf("%.2lf ",results[i]);
}
again=0;//no more iteration required
}
//otherwise print error message and prompt again to enter values
else{
printf("Sorry! Please enter row & column value less than 10");
}
}while(again==1);

return 0;
}

Output

Name - xyz
netid - xyz
lab time - xyz
Description of the program - This program takes the room chart from user and sho
ws the average length of the names per length(provided by user)

Please enter number of rows : 3
Please enter number of columns : 3

Please enter the values in mychart one by one
name 1
a 2
a
3
4
5
2
3
4
Please enter the length : 3

Chart is :

### 1 2 3
1 name 1 a 2 a
2 3 4 5
3 2 3 4
The Number of names in the chart is : 9
The Average length of the names per length=3
3.33
1.00
1.00