Question

ow cuma mi Write a program that defines a 2D boolean ve indices of the array i& represent people. The l friends and false (0)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
using namespace std;
void printArray(bool friends[][5],int rowSize)
{   
// initially print # |
cout<<"# | ";
for (int i=0;i<5;i++)
// then numbering
cout<<i<<" ";
// then line change
cout<<endl;
cout<<"-----------------"<<endl;
for(int i=0;i<rowSize;i++)
{   
// every row start with i |
cout<<i<<" | ";
for(int j=0;j<5;j++)
{ // if i,j is friend then print * otherwise space
if(friends[i][j]==1)
cout<<"* ";
else
cout<<" ";
  
}
cout<<endl;
}
}
bool commonFriends(bool friends[][5],int rowSize,int i,int j,int &k)
{
for(int col=0;col<5;col++)
{   
// check if both i,j have value 1 at same column if yes then it is common friend
if(friends[i][col]==1 && friends[j][col]==1)
{
k=col;
return 1;
}
}

this is working code if you have some difficulty so i am providing screenshot of my code

1 include <iostream> 2 using namespace std; 3 void printArray (bool friends [][5], int rowSize) 4 { // initially print # | cocout<<endl; 31 32 bool commonFriends (bool friends [][5], int rowSize, int i, int j, int &k) 33- { 34 for(int col=0;col<5;col54 51. int main() { const int rowSize =5; 53 const int colSize =5; //declaration of matrix 55 bool friends[rowSize][colSize]=output is

Output: # 1 0 1 2 3 4 ------ 1 * * 2. * 3 | * 4 * * * enter two people there is common friends between 4 and 3 is o

Add a comment
Know the answer?
Add Answer to:
ow cuma mi Write a program that defines a 2D boolean ve indices of the array...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I NEED HELP IN MAZE PROBLEM. Re-write the following program using classes. The design is up...

    I NEED HELP IN MAZE PROBLEM. Re-write the following program using classes. The design is up to you, but at a minimum, you should have a Maze class with appropriate constructors and methods. You can add additional classes you may deem necessary. // This program fills in a maze with random positions and then runs the solver to solve it. // The moves are saved in two arrays, which store the X/Y coordinates we are moving to. // They are...

  • == Programming Assignment == For this assignment you will write a program that reads in the...

    == Programming Assignment == For this assignment you will write a program that reads in the family data for the Martian colonies and stores that data in an accessible database. This database allows for a user to look up a family and its immediate friends. The program should store the data in a hashtable to ensure quick access time. The objective of this assignment is to learn how to implement and use a hashtable. Since this is the objective, you...

  • Write a program that supports the three phases (setup, voting and result-tallying) which sets up and...

    Write a program that supports the three phases (setup, voting and result-tallying) which sets up and executes a voting procedure as described above. In more details: You can start with the given skeleton (lab6_skeleton.cpp). There are two structures: Participant structure, which has the following members: id -- an integer variable storing a unique id of the participant (either a candidate or a voter). name -- a Cstring for storing the name of the participant.. hasVoted -- a boolean variable for...

  • How to write the insert, search, and remove functions for this hash table program? I'm stuck......

    How to write the insert, search, and remove functions for this hash table program? I'm stuck... This program is written in C++ Hash Tables Hash Table Header File Copy and paste the following code into a header file named HashTable.h Please do not alter this file in any way or you may not receive credit for this lab For this lab, you will implement each of the hash table functions whose prototypes are in HashTable.h. Write these functions in a...

  • I need help modifying this program. How would I make sure that the methods is being...

    I need help modifying this program. How would I make sure that the methods is being called and checked in my main method? Here is what the program needs to run as: GDVEGTA GVCEKST The LCS has length 4 The LCS is GVET This is the error that I'm getting: The LCS has length 4 // I got this right The LCS is   //the backtrace is not being called for some reason c++ code: the cpp class: /** * calculate...

  • Assignment Overview In Part 1 of this assignment, you will write a main program and several...

    Assignment Overview In Part 1 of this assignment, you will write a main program and several classes to create and print a small database of baseball player data. The assignment has been split into two parts to encourage you to code your program in an incremental fashion, a technique that will be increasingly important as the semester goes on. Purpose This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of...

  • Problem Set 2: Inheritance and Method Overriding The goal of this problem set is to apply...

    Problem Set 2: Inheritance and Method Overriding The goal of this problem set is to apply inheritance and method overriding in order to create a hierarchy of array sorters. There exist many algorithms to sort arrays. In this problem set, we are especially interested in “in-place” sorting algorithms like Selection Sort and Insertion Sort. In-place sorting refers to an approach in which we perform the sorting steps on the underlying array rather than using extra storage. When using object-oriented design,...

  • This C++ Program consists of: operator overloading, as well as experience with managing dynamic memory allocation...

    This C++ Program consists of: operator overloading, as well as experience with managing dynamic memory allocation inside a class. Task One common limitation of programming languages is that the built-in types are limited to smaller finite ranges of storage. For instance, the built-in int type in C++ is 4 bytes in most systems today, allowing for about 4 billion different numbers. The regular int splits this range between positive and negative numbers, but even an unsigned int (assuming 4 bytes)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT