Starting from:
$35

$29

Programming Assignment 1 Solution

Write a C++ program to do the following:




Create two 2D Arrays ( Array_1 , Array_2 ). Each array is of size 3 x3.
Write a function to populate both arrays withdistinct randomnumbers
that are between 1 and 12.

Write a function to display botharrays.
Write a function to add Array_1 to Array_2 and place the result in Array_3. DisplayArray_3.
Write a function to multiply Array_1 by Array_2 and place the result in Array_3. DisplayArray_3.
Write a function to display the transposed of Array_1.
Write a function to display the determinant ofArray_1.
Write a display the sum of elements of each row inArray_1.
Write a display the sum of elements of each column inArray_1.
Write a display the sum of both diagonalelementsin Array_1.
Use a function to determine whether Array_1 is aspecial array.special Arrayis an arrangement of distinct numbers (i.e. each numberis
used once), usually integers, in a array grid, where the numbers in each row, and in each column, and the numbers in the main and secondary diagonals, all add up to the same number.




Repeat steps 2 – 11 until the user terminates theprogram.
Note :




-­‐Use the following formula to findthedeterminant of 3 by3Array:



If Array:










Then




|A| = a(ei − fh) − b(di − fg) + c(dh − eg)







-­‐Use the following formula in order to find the specialnumber



SpecialNumber = ( n ( n^2 + 1 ) ) /2







Example of a Special Array




At the beginning of your program ( andbeforethe #include statement ), include the following:




Header comments(file documentation block) should be at the top of each file and should contain: Author / s, Due Date, Assignment Number, Course number and section, Instructor, and a brief description of the purpose of the code in the file. For example :



// Author / s : (Your nameshere!!)

// Due Date:

// Programming Assignment Number1

// Spring 2018-­‐CS3358 -­‐ SectionNumber

//

// Instructor: HusainGholoom.

//

// <Brief description of the purpose of theprogram







Variable names :




Must bemeaningful.
The initial letter should be lowercase, following words should be capitalized, noother caps or punctuation(i.e. weightInPounds ).
Each variable must be declared on a separate line with a descriptivecomment.






Named constants :




Use for most numericliterals.
All capitals with underscores(i.e. TX_STATE_SALES_TAX )
Should occur at top of function, or global (only ifnecessary)



Line lengthof source code should be no longer than 80 characters (no wrapping of lines).




Indentation :




Use 2-4 spaces (but be consistent throughout yourprogram).
Indent blocks, within blocks,etc.
Use blank lines to separatesections.



Comments for variables :




All variable definitions should be commented as follows:




int gender; // integer value for thegender,

// 1 = Male , 2 = Female ,







Rules:




Your programmust compileand run using latest version of codeblocks underwindows.
Yourprogrammustbedocumentedaccordingthestyleabove.Seethewebsiteforthesample programming styleprogram.
Mustuserandomnumbergeneratortogeneratethe3-­‐digit number .
Mustuseat least10 functions other than your mainfunction.
You are not allowed to use global Arrays , global variables … etc. You are also not allowed to classes andpointers.
You must use the appropriate libraries in writing thisprogram.
Must properly format the output as it is shown on the sample run below. Replace my name with yourname
You must name your program as:



oSP18_3358_S#_LastName_FirstName_PG1.cpp // S# is sectionNumber




Where LastName is your Last Name and FirstName is your First Name, and S# is your section number. For example , the file name should look something like :




SP18-­‐3358_0_Gholoom_Husain_PG1.cpp(not.cbp)orSP18-­‐3358_1_Gholoom_Husain_PG1.cpp(not.cbp)orSP18-­‐3358_2_Gholoom_Husain_PG1.cpp(not.cbp)




You must upload your programs no later than the starting of class time on the due date.No late assignments will be accepted.Everyone must upload their programelectronically.



Use Tracks To upload your program.

You mustalsoturn in hard copy of your source code no later than the starting of class time on the due date . should the hard copy consist of more than one page , then , the hard copy must bestapled. if you are unable to turn in a printout during class, you can take the program to the computer science department and hand it to the front desk personal (Comal 211 ) before the deadline. Make sure that the front office stamps the program. Make sure that include the date and time. Finally ,make sure that they place the program in my mailbox.One hard copy per group.



DO NOTslide your program under my office door – It willNOTbe accepted







The following points will be deducted if :




Incorrect file format such asuploading.cbp instead of .cpp , missing electronic copy , missing the hardcopy using .h and .cpp files , CompilationErrors , Using globalvariables,global arrays ,vectorsorglobal vectors …etc ( - 10 points)






Other( 0.5 pointeach) :



LogicalErrors
Unable to read the source code due to unclearprinting
Incorrect program filename.
Incorrect outputformat.
More than one hardcopy per group or Hard copy is notstapled.
Incorrect Stylesuch as but not limited toMissing outputheader
, output footer , comments or program documentations , missing roster number , missingsectionnumber, … etc
Sample Run







WelcometomyArray program.Thefunctionoftheprogramisto







Createan2Arrays(Array_1,Array_2).EachArrayisofsize3x3.
Populateboth Arrays with distinctrandomnumbers thatarebetween 1and
12. DisplaybothArrays.

Addingandmultiplying Array_1andArray_2.
Displaying thetransposedandthedeterminate of Array_1.
Displaying the sum ofelementsof eachrowof Array_1, displaying the sum of elements ofeachcolumnof Array_1 , displaying the sum of bothdiagonalelements of Array_1.
Finally, determining whetherornot Array_1 isspecialarray.



Repeating theabovesteps until the userterminatestheprogram.









Array_1 :







8
1
6
3
5
7
4
9
2












Array_2 :







1
6
8


4
10
3
2
5
7



Sum



ofArray



1



and



Array 2



9



7



14




7
15
10




6
14
9







Product ofArray1 and Array 2





24
88
109
37
103
88
44
124
73






Transpose ofArray1




8
3
4
1
5
9
6
7
2






Determinate ofArray1 = -360








Sum
of
numbers
in
Row
#
1
in
Array
1
=
15
Sum
of
numbers
in
Row
#
2
in
Array
1
=
15
Sum
of
numbers
in
Row
#
3
in
Array
1
=
15



Sum



of



numbers



in



Column



#



1



in



Array



1



=



15
Sum
of
numbers
in
Column
#
2
in
Array
1
=
15
Sum
of
numbers
in
Column
#
3
in
Array
1
=
15









Sum
of
numbers
in
firstdiagonal
inArray
1
=
15
Sum
of
numbers
in
seconddiagonal
inArray
1
=
15



The The



specialnumberfor ArrayaboveisSpecialArray






1
is 15









WouldliketocheckanotherArray-EnteryorYforyes orn|N for no y




Array_1 :







1
3
5
2
4
10
6
7
12









Array_2 :







9 1 3




6 10 2




4 5 7










SumofArray1 and Array 2







10 4 8




8 14 12




10 12 19










Product ofArray1 and Array 2




47
56
44
82
92
84
144
136
116









Transpose ofArray1





1
2
6
3
4
7
5
10
12






Determinate ofArray1 = 36










Sum
of
numbers
in
Row
#
1
in
Array
1
=
9
Sum
of
numbers
in
Row
#
2
in
Array
1
=
16
Sum
of
numbers
in
Row
#
3
in
Array
1
=
25



Sum



of



numbers



in



Column



#



1



in



Array



1



=



9
Sum
of
numbers
in
Column
#
2
in
Array
1
=
14
Sum
of
numbers
in
Column
#
3
in
Array
1
=
27







Sum
of
numbers
in
firstdiagonal
inArray
1
=
15
Sum
of
numbers
in
seconddiagonal
inArray
1
=
17






Thespecialnumberis 15







TheaboveisnotaspecialArray







WouldliketocheckanotherArray-EnteryorYforyes orn|N for no 5

Error***Invalidchoice -Mustenter y|Y | n| N







WouldliketocheckanotherArray-EnteryorYforyes orn|N for no h

Error***Invalidchoice -Mustenter y|Y | n| N







WouldliketocheckanotherArray -EnteryorYforyesorn|N for no n







This algorithmisimplementedByHusainGholoom

More products