






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Five C++ code snippets demonstrating array manipulation using dynamic memory allocation and file I/O using the standard library. The first code snippet initializes, prints, and deep copies an integer array. The second code snippet reads student marks from a text file and stores the data in dynamic arrays. The third code snippet copies a character string to a dynamic array. The fourth code snippet performs matrix addition using dynamic memory allocation. The fifth code snippet inputs and displays a 2D integer matrix with varying row sizes.
Typology: Assignments
1 / 12
This page cannot be seen from the preview
Don't miss anything!







#include
#include
if (Marks[i][j] >= 50 && Marks[i][j] <= 79) { Grades[i][j] = 'C'; } if (Marks[i][j] >= 33 && Marks[i][j] <= 49) { Grades[i][j] = 'D'; } if (Marks[i][j] >= 0 && Marks[i][j] <= 32) { Grades[i][j] = 'F'; } } } k++; } for (i = 0; i < Students; i++) { for (j = 0; j < Labs + 1; j++) { cout << Grades[i][j] << " "; } cout << endl; } loop = false; } if (!loop) { break; } } } } else { cout << "Files does not find "; } file.close(); system("pause"); }
#include
cout << endl; } int main() { int sizeoffirstmatrix; int sizeofsecondmatrix; cout << "Size of first matrix:"; cin >> sizeoffirstmatrix; cout << "Size of second matrix:"; cin >> sizeofsecondmatrix; if (sizeoffirstmatrix == sizeofsecondmatrix) { int **matrix1 = new int *[sizeoffirstmatrix]; int **matrix2 = new int *[sizeofsecondmatrix]; for (int i = 0; i<sizeoffirstmatrix; i++) { matrix1[i] = new int[sizeoffirstmatrix]; matrix2[i] = new int[sizeofsecondmatrix]; } cout << " entries of first matrix" << endl; Input(matrix1, sizeoffirstmatrix, sizeoffirstmatrix); Display(matrix1, sizeoffirstmatrix, sizeofsecondmatrix); cout << " entries of second matrix" << endl; Input(matrix2, sizeoffirstmatrix, sizeoffirstmatrix); Display(matrix2, sizeofsecondmatrix, sizeofsecondmatrix); cout << " ADDITION" << endl; int **sum = Sum(matrix1, sizeoffirstmatrix, sizeoffirstmatrix, matrix2, sizeofsecondmatrix, sizeofsecondmatrix); Display(sum, sizeoffirstmatrix, sizeoffirstmatrix); } else cout << "error!! size of matrices are not same \n"; system("pause"); return 0; }
for (int j = 0; j<colum[i]; j++) { cout << matrix[i][j] << " "; } cout << endl; } cout << endl; } int main() { int row, colum; cout << "Enter the Total Rows :"; cin >> row; int **matrix = new int *[row]; int *r = new int[row]; for (int i = 1; i<row; i++) { cout << "Enter colum of row " << i << ":"; cin >> colum; r[i] = colum; matrix[i] = new int[colum]; } cout << endl; Input(matrix, row, r); cout << "Matrix is ... " << endl; Display(matrix, row, r); system("pause"); return 0; }