Graded Lab 3
Graded Lab 3
Marks: 3+3+4=10
Task 1
Write a program in C++ that reads data from a file named “data.txt”. Create dynamic memory
according to the data. Now your task is to perform the following tasks. You have to use three user
define functions to perform the tasks.
Example
data.txt
2 4 3 1
3 9 2 3
9 7 1 5
8 6 7 8
Output:
Sum row wise: 10, 17, 22, 22, 29
Sum col wise: 22, 26,13,17
Sum diagonal wise: 20
SOLUTION:
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
int main()
{
int array[4][4];
ifstream read;
read.open("data.txt");
while (!read.eof())
{
for (int i = 0; i<4; i++)
{
for (int j = 0; j<4; j++)
{
read >> array[i][j];
}
}
}
rowsum(array);
columnsum(array);
diagonalsum(array);
system("pause");
return 0;
}