Answer to Question #179173 in C++ for shraddha

Question #179173

Test #1: Find the bug

#include <iostream>

#include <vector>

std::vector<std::string> getUniqueBrands(const std::vector<std::string>& brand1, const std::vector<std::string>& brand2)

{

throw std::logic_error("yet to be implemented");

}

int main()

{

std::vector<std::string> brand1 = {"LOUIS_VUITTON", "HERMES", "PRADA"};

std::vector<std::string> brand2 = {"GUCCI", "PRADA", "HERMES"};

std::vector<std::string> result = getUniqueBrands(brand1, brand2);

for(auto element : result)

{

std::cout << element << ' ';

// should print GUCCI HERMES LOUIS_VUITTON PRADA

}

}

Test #3:

1. Create a matrix of size n x n, where n is the user input. 2. Populate the matrix with random integers (without taking user input). 3. Print the diagonal elements of the matrix from top left to bottom right corner.


1
Expert's answer
2021-04-07T17:41:11-0400
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
    int n;
    cout<<"Enter the size of array\n ";
    cin>>n;
    int a[n][n];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            a[i][j]=rand();
        }
    }
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(i==j)
            {
                cout<<a[i][j]<<" ";
            }
        }
        cout<<"\n";
    }
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS