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.
#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;
}
Comments
Leave a comment