c++complete and change
#include <iostream>
using namespace std;
int sumbyrow(int* m, int ncol, int row)
{
int total = 0;
for (int i = 0 i < ncol; i++) {
total += m[row * ncol + i];
}
return total;
}
int sumBCol(int* m, int nrow, int ncol, int col)
{
int total = 0;
for (int j = 0; < j nrow; j++) {
total += m[j * ncol + col];
}
return total;
}
int sumBYLeftDiag(int* m, int ncol)
{
int total = 0;
for (int i = 0, j = ncol - 1; i < ncol && j >= 0; i++, j--) {
total += m[i * ncol + j];
}
return total;
}
bool hasDuplicates(int* m, int row) {
int flatArray[row * row];
int k = 0
for (int i = 0; i < row; i++) {
for (int j = 0; j < row; j++) {
flatArray[k++] = m[i * row + j];
}
}
for (int i = 0; i < (row * row); i++) {
for (int j = i + 1; j < (row * row); j++) {
if (flatArray[i] == flatArray[j])
return true;
}
}
return flase;
}
bool isMagicMatrix(int* m, int nrow, int ncol) {
if (hasDuplicate(m, nrow), int ncol{
return false;
}
if (sumByleftDiag(m, nrow) != sumByRightDiag(m, nrow)) {
return false;
}
for (int i = 0; i < nrow; i++) {
if (sumByrow(m, nrow, ncol, i) != sumByCol(m, nrow, ncol, i)) {
return false;
(change here)
}
}
return true;
}
int main()
{
int main m[3][3] = {
{ 8, 1, 6},
{ 3, 5, 2},
{ 4, 9, 2},
};
(1) 2 + 5 + 9 == 6 + 5 + 7
(2) 2 + 3 + 6 == 2 + 4 + 7
4 + 5 + 5 == 3 + 5 + 8
7 + 8 + 9 == 6 + 5 + 9
(3) 2 + 5 + 9 == 2 + 4 + 7
* /
/*
*/
int m2[2][2] = {
{ 2, 3 }, // 0
{ 4, 5 }
// 0 1
};
/* { 2, 3, 6, 4, 5, 5, 7, 8, 9 } */
/* { 2, 3, 4, 5 } */
int a[2];
int* p = a;
check((int*)m1, 3);
check((int*)m2, 2);
int size = sizeof(*m) / sizeof(int);
cout << "SIZE OF MATRIX" "<<size<<"X"<<size<<endl;
if (isMagicMatrix((int*)m, size, size) == 0{
cout << "NO MAGIC SQUARE";
}
else {
cout << "MAGIC SQUARE";
}
return 0;
}
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 1 images
- C programming #include <stdio.h>int main() {int i, j, n ;printf("height? ") ;scanf("%2d", &n) ;for (i = 1 ; i <= n ; i++) {// printf("%d: ", i) ;for (j = 1 ; j <= i ; j++) {// Pick *one* of the following// printf("%d", j % 10) ;printf("*") ;}printf("\n") ;}return 0 ;} How can I get output like this by editing the given programming -- height? 5************************* and then how can I get the following?- height? 7 1 123 12345 1234567 123456789 12345678901 1234567890123arrow_forwardC++ need help with part d to g only Assume the Product structure is declared as follows: struct Product { string description; // Product description int partNum; // Part number double cost; // Product cost }; (c) Declare a dynamic array of Products of size 5 and name it ”items”. Then initilize it with user input values. (d) Write a print function (not as a member of the struct) and pass a pointer to the pointer that points to the array (double pointer) and print all the items of the array in that function. (e) Define a max function (not as a member of the struct) that gets an array of items as an input and returns a pointer to the max element of the array. (f) Declare a 3 by 3 two dimensional dynamic array and populate it. (g) Define an output function that takes a stream object and a pointer to a 2D array as arguments and outputs data members of objects in format of 3*3 table into the given stream. Test your function both with an output file…arrow_forwardC++ Program #include <iostream>#include <cstdlib>#include <ctime>using namespace std; int getData() { return (rand() % 100);} class Node {public: int data; Node* next;}; class LinkedList{public: LinkedList() { // constructor head = NULL; } ~LinkedList() {}; // destructor void addNode(int val); void addNodeSorted(int val); void displayWithCount(); int size(); void deleteAllNodes(); bool exists(int val);private: Node* head;}; // function to check data exist in a listbool LinkedList::exists(int val){ if (head == NULL) { return false; } else { Node* temp = head; while (temp != NULL) { if(temp->data == val){ return true; } temp = temp->next; } } return false;} // function to delete all data in a listvoid LinkedList::deleteAllNodes(){ if (head == NULL) { cout << "List is empty, No need to delete…arrow_forward
- Write a function getNeighbors which will accept an integer array, size of the array and an index as parameters. This function will return a new array of size 2 which stores the neighbors of the value at index in the original array. If this function would result in returning garbage values the new array should be set to values {0,0} instead of values from the array.arrow_forwardC programmingarrow_forward#include <iostream> #include <iomanip> #include <string> using namespace std; struct Teletype { string name; string phonenum; Teletype *nextaddr; }; void populate(Teletype *); void displayrecord(Teletype *); //void insertrecord(Teletype *); // create //void removerecord(Teletype *); //create //void modifyrecord(Teletype *); // create //int find(TeleType *, string); // Extra Credit create bool check(); int main() { int location = 0; int count = 0; char answery_n; Teletype *list, *current; list = new Teletype; current = list; cout << "Please "; do { count++; populate(current); if (check() == false) { cout << " Not storage available" << endl; } else { current->nextaddr = new Teletype; current = current->nextaddr;…arrow_forward
- >> IN C PROGRAMMING LANGUAGE ONLY << COPY OF DEFAULT CODE, ADD SOLUTION INTO CODE IN C #include <stdio.h>#include <stdlib.h>#include <string.h> #include "GVDie.h" int RollSpecificNumber(GVDie die, int num, int goal) {/* Type your code here. */} int main() {GVDie die = InitGVDie(); // Create a GVDie variabledie = SetSeed(15, die); // Set the GVDie variable with seed value 15int num;int goal;int rolls; scanf("%d", &num);scanf("%d", &goal);rolls = RollSpecificNumber(die, num, goal); // Should return the number of rolls to reach total.printf("It took %d rolls to get a \"%d\" %d times.\n", rolls, num, goal); return 0;}arrow_forwardC++ complete magic Square #include <iostream> using namespace std; /*int f( int x, int y, int* p, int* q ){if ( y == 0 ){p = 0, q = 0;return 404; // status: Error 404}*p = x * y; // product*q = x / y; // quotient return 200; // status: OK 200} int main(){int p, q;int status = f(10, 2, &p, &q);if ( status == 404 ){cout << "[ERR] / by zero!" << endl;return 0;}cout << p << endl;cout << q << endl; return 0;}*/ /*struct F_Return{int p;int q;int status;}; F_Return f( int x, int y ){F_Return r;if ( y == 0 ){r.p = 0, r.q = 0;r.status = 404;return r;}r.p = x * y;r.q = x / y;r.status = 200;return r;} int main(){F_Return r = f(10, 0);if ( r.status == 404 ){cout << "[ERR] / by zero" << endl;return 0;}cout << r.p << endl;cout << r.q << endl;return 0;}*/ int sumByRow(int *m, int nrow, int ncol, int row){ int total = 0;for ( int j = 0; j < ncol; j++ ){total += m[row * ncol + j]; //m[row][j];}return total; } /*…arrow_forwardC++ languagearrow_forward
- C++ program #include<iostream> #include<fstream> #include<string> using namespace std; const int NAME_SIZE = 20; const int STREET_SIZE = 30; const int CITY_SIZE = 20; const int STATE_CODE_SIZE = 3; struct Customers { long customerNumber; char name[NAME_SIZE]; char streetAddress_1[STREET_SIZE]; char streetAddress_2[STREET_SIZE]; char city[CITY_SIZE]; char state[STATE_CODE_SIZE]; int zipCode; char isDeleted; char newLine; }; void add_data(int no_of_records, ofstream& fout) { struct Customers c; cout << "Enter the Customer data:" << endl; cout << "Name:"; cin >> c.name; cout << "Street Address 1:"; cin >> c.streetAddress_1; cout << "Street Address 2:"; cin >> c.streetAddress_2; cout << "City:"; cin >> c.city; cout << "State:"; cin >> c.state; cout << "Zip Code:"; cin >> c.zipCode; cout << endl; c.customerNumber = no_of_records; c.isDeleted = 'N'; c.newLine = '\n'; cout…arrow_forwardExplain the concept of two-way data binding with custom data types and complex objects. What challenges may arise when implementing it?arrow_forwardIn the C programming language, if all function prototypes are listed at the top of your code, outside and above all functions, you do not need to worry about the order of the function definitions within the code. True Falsearrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education