CMP120 - Introduction to Computer Science I: Homework 5 - Array Manipulation in C++, Assignments of C programming

Homework about Double arrays and loops

Typology: Assignments

2021/2022

Uploaded on 03/12/2023

mariam-gharaibeh
mariam-gharaibeh 🇦🇪

6 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Name : Mariam Bashar
ID : (g00093023)
American University of Sharjah
College of Engineering
Department of Computer Science and Engineering
CMP120 – Introduction to computer science I
Spring 2022
Homework 5
Professor : Dr. Tamer Shanableh
Student Major : Computer Science
Section Number : 09
Submission date: 4 -4 -2022
pf3
pf4
pf5

Partial preview of the text

Download CMP120 - Introduction to Computer Science I: Homework 5 - Array Manipulation in C++ and more Assignments C programming in PDF only on Docsity!

Name : Mariam Bashar

ID : (g00093023)

American University of Sharjah

College of Engineering

Department of Computer Science and Engineering

CMP120 – Introduction to computer science I

Spring 2022

Homework 5

Professor : Dr. Tamer Shanableh Student Major : Computer Science Section Number : 09 Submission date: 4 -4 -

 Solution of Program

#include using namespace std; void print_arr( double arr[][ 8 ] , const int Rs , const int Cs){ for ( int r = 0 ; r < Rs; r++) { for ( int c = 0 ; c < Cs; c++) { cout << arr[r][c] << " "; } cout << "\n"; } cout << "\n"; } void print_quarter( double arr_quarter[][ 2 ], const int Rs, const int Cs) { for ( int r = 0 ; r < Rs; r++) { for ( int c = 0 ; c < Cs; c++) { cout << arr_quarter[r][c] << " "; } cout << "\n"; } cout << "\n"; } //-------------------------------------------------------------- int main () { const int Rs = 8 , Cs = 8 ; double arr[Rs][Cs]; const int Rs_quart = Rs / 4 , Cs_quart = Cs / 4 ; double arr_quarter[Rs / 4 ][Cs / 4 ]; //fill in the array with some data for ( int r = 0 ; r < Rs; r++) for ( int c = 0 ; c < Cs; c++) arr[r][c] = r * 8 + c; cout << "Print array : "<<endl; print_arr( arr,Rs , Cs); //Diagonal elements cout<< "Diagonal elements : ";

arr[r][c+ 2 ] = arr[r][c+ 3 ] = arr[r+ 1 ][c] = arr[r+ 1 ][c+ 1 ] = arr[r+ 1 ][c+ 2 ] = arr[r+ 1 ][c+ 3 ] = arr[r+ 2 ][c] = arr[r+ 2 ][c+ 1 ] = arr[r+ 2 ][c+ 2 ] = arr[r+ 2 ][c+ 3 ] = arr[r+ 3 ][c] = arr[r+ 3 ][c+ 1 ] = arr[r+ 3 ][c+ 2 ] = arr[r+ 3 ][c+ 3 ] = arr_quarter[r_quart][c_quart++]; } r_quart++; c_quart = 0 ; } print_arr( arr,Rs , Cs); }

 Picture of solution