Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

c++ please show steps Create a class out of the structure privatizing the data and adding setter and getter functions. Main.cpp /* * File: main.cpp

c++ please show steps Create a class out of the structure privatizing the data and adding setter and getter functions.

Main.cpp

/* * File: main.cpp * Author: * Created on February 13th, 2019, 1:30 M * Purpose: */

//System Libraries Here #include #include #include using namespace std;

//User Libraries Here #include "Triangle.h"

//Global Constants Only, No Global Variables //Like PI, e, Gravity, or conversions

//Function Prototypes Here Trngl *fillStr(int); void prntStr(Trngl *); void destroy(Trngl *);

//Program Execution Begins Here int main(int argc, char** argv) { //Set the random number seed srand(static_cast(time(0))); //Declare all Variables Here int row=10; //Input or initialize values Here Trngl *triangle=fillStr(row); //Output Located Here prntStr(triangle); //Return Memory destroy(triangle);

//Exit return 0; }

void destroy(Trngl *tri){ for(int row=0;rowsize;row++){ delete []tri->data[row]; } delete []tri->data; delete tri; }

void prntStr(Trngl *tri){ cout<size;row++){ for(int col=0;coldata[row][col]<<" "; } cout<

Trngl *fillStr(int n){ //Allocate a structure to hold the Matrix Trngl *tri=new Trngl; //Create the 2-D allocated pointer tri->data=new int*[n]; for(int row=0;rowdata[row]=new int[row+1]; } tri->size=n; //Fill the array with values for(int row=0;rowdata[row][col]=rand()%90+10; } } //return the Array pointer return tri; }

Triangle.h

/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */

/* * File: Triangle.h * Author: * * Created on February 13, 2019, 1:56 PM */

#ifndef TRIANGLE_H #define TRIANGLE_H

struct Trngl{ int size; int **data; };

#endif /* TRIANGLE_H */

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning Apache Cassandra Development

Authors: Vivek Mishra

1st Edition

1484201426, 9781484201428

More Books

Students also viewed these Databases questions