ECE 220 Lecture Notes - Lecture 23: Stack-Based Memory Allocation, C Mathematical Functions

55 views3 pages

Document Summary

// . hh file class complex double real_part, imag_part; // instance variables public: // accessor functions double getreal(); double getimag(); void setreal(double real); void setimag(double imag); // stack allocated, complex is a class, similar to a structure. Complex::complex() { real_part = real_part; double complex::getimag() { return imag_part; void complex::setreal(double real) { real_part = real; vpod complex::setimag(double imag) { imag_p[art = imag; double complex::abs() { return sqrt(real_part*real_part + imag_part*imag_part); int main() { // same as complex b(a); c. operator = (a); // means c = a; printf(%lfn, a. abs()); std::cout << a. abs() << std::endl; // can use end of line or n; c++ io. // head file class intvector { int length; int *vector; public: Intvector::intvector() { length = 0; vectr = null; Intvector::intvector(int len) { length = len; vector = new int[len]; // allocate memory. Intvector::intvector(const intvector &x) { int i; length = x. length; if (x. length) { vector = new int[length]; for (i = 0; i

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents