S24 PF AFour Part One
S24 PF AFour Part One
S24 PF AFour Part One
Problem statement:
In this Set One, you will dry run the following Pieces of Code
Problem statement:
In this Set One, you will write the code of ALL functions used in the main (Function
prototypes are given)
Use of any of the following is zero marks in the whole Set TWO
int main()
{
char ** words = nullptr;
int noOfWords = 0;
/*
asssume file "words.txt" has the following words:
int main()
{
int ** matrix = nullptr;
int noOfRows = 0;
int noOfColumns = 0;
/*
asssume file "matrix.txt" has the following values:
11 12 13 14 15,
21 22 23 24 25,
31 32 33 34 35,
41 42 43 44 45,
*/
ifstream R("matrix.txt");
matrix = read(R, noOfRows, noOfColumns);
R.close();
display(matrix, noOfRows, noOfColumns);
return 0;
}
int ** read(ifstream rd, int rn, int cn)
{
int ** array2D = nullptr;
char * str = new char[10];
initialize(str, '\0');
int m = 0;
int n = 0;
while(rd >> str)
{
if(m == 0 && n == 0)
{
addRows(array2D, rn, 0, 1);
}
shrink(str);
int ind = 0;
bool found = isFound(str, '.', ind);
if(found)
{
removeChar(str, '.');
}
int value = cstring2int(str);
addColumns(array2D[m], cn, 1);
array2D[m][n] = value;
n++;
if(found)
{
addRows(array2D, rn, cn, 1);
m++;
}
}
}