Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

oo T-Mobile LTE 10:21 AM Google Maps is Using Your Location 86%- learn.kent.edu

ID: 674951 • Letter: O

Question

oo T-Mobile LTE 10:21 AM Google Maps is Using Your Location 86%- learn.kent.edu 63002 Algonitms and Programning Project 1 Pascal's Triangle Project Objectives The goal of this project is to gain more practice with List. In Python, the List type is a container that holds a number of other objects, in a gven ceder. This data structure is so useful and powerful that you can find it in almost every algorithm Pascars triangle You can get the detailed explanation In this project, we want to generate from Wikipedia The figure below is a simple Pavcal's triangle whose height is 7 1 5 10 10 5 1 1 6 15 20 15 6 1 Project Specification 1 Your program will ask the user to input a positive number that wil be used as the height of triangle.Check for this condition To generate the triangle, you start from the first row, which is always 1, and the second row which is always 11 2. 3. After the first two rows, each row at level h is generated from the values at row b-1 Note that the leftmost number and the rightmost number in any row are always 2 Note that, in row k, there are numbers. 4 We will use a list to represent a row, Because the triangle consists of multiple rows, we will require another list to hold all the lists that makes the triangle rows. Thus, we wil have a list of lists. 5. You should include specifications of the function (Preconditions and Postconditions) 6 You should also write test cases for this peogram. 7. You should use assert statements in your code. You should test your method thoroughly.

Explanation / Answer

#include <iostream>
#include<vector>
using namespace std;
vector<vector<int> > getRow(int A) {
// Do not write main() function.
// Do not read input, instead use the arguments to the function.
// Do not print the output, instead return values as specified
// Still have a doubt. Checkout www.interviewbit.com/pages/sample_codes/ for more details
vector<vector<int> > rows(A);
vector<int> previousrow(1);
previousrow[0] = 1;
rows[0] = previousrow;
for(int i = 1; i < A; i++){
vector<int> row(i+1);
row[0] = previousrow[0];
row[i] = previousrow[i - 1];
for(int j = i - 1 ; j > 0 ; j--){
row[j] = previousrow[j] + previousrow[j - 1];
}
for(int i = 0 ; i < row.size(); i++)  
           cout<<row[i]<<" ";
       cout<<endl;
previousrow = row;
       rows[i] = row;   
      
}
return rows;
}

int main(){
   vector<vector<int> > a = getRow(5);
   for(int k = 0; k < a.size(); k++)
   {
       for(int i = 0 ; i < a[k].size(); i++)  
           cout<<a[k][i]<<" ";
       cout<<endl;
   }
}