0% found this document useful (0 votes)
72 views2 pages

ECE391: Computer System Engineering Homework 1: C++ Code Variables Check If Error

This document contains a homework assignment for a Computer Systems Engineering course. It includes 9 questions covering topics like C++ code analysis, array initialization, 2D array printing, pass by value vs reference, class constructors, and operator overloading. The instructor is listed as Dr. Truong Quang Vinh from Ho Chi Minh City University of Technology, Department of Electronics and Electrical Engineering.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views2 pages

ECE391: Computer System Engineering Homework 1: C++ Code Variables Check If Error

This document contains a homework assignment for a Computer Systems Engineering course. It includes 9 questions covering topics like C++ code analysis, array initialization, 2D array printing, pass by value vs reference, class constructors, and operator overloading. The instructor is listed as Dr. Truong Quang Vinh from Ho Chi Minh City University of Technology, Department of Electronics and Electrical Engineering.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Ho Chi Minh City University of Technology Department of Electronics and Electrical

Engineering

ECE391: Computer System Engineering

Homework 1
1. Determine the content of variables after the following C++ code

C++ code Variables Check if error


int a[] = {1,4,7,8,9}; a[] = {1,4,7,8,9}; 
int b[] = {2,3,6,7,11}; b[] = {2,3,6,7,11};
int *p, *q;
int X;
p = a;
q = b;
*p = 5; a[] = 
*q = 8; b[] =
X = **&*&p; X=5 
X = *&*q; X=8 
X = ++p; X= 
X = *p--; X=5 
p = *&*q; p= 

2. Consider the following attempt to allocate a 10-element array of pointers to doubles and
initialize the associated double values to 0.0. Rewrite the following incorrect code
double* dp[10];
for (int i=0; i<10; i++) dp[i] = 0.0;
3. Write a C++ function printArray(A, m ,n) that prints an m´n two dimensional array A of integers,
declared to be “int** A”, to the standard output. Each of the m rows should appear on separate
line
4. What is different about the behavior of the following two function f() and g() which increment a
variable and print its value?
void f(int x)
{ std::cout << ++x;}
void g(int& x)
{ std::cout << ++x;}
5. Write a C++ class, AllKinds, that has three member variables of type int, long, and float,
respectively. Each class must include a constructor function that initializes each variable to a
nonzero value, and each class should include functions for setting the value of each type, and
computing and returning the sum of each possible combination of types.
6. Write a short C++ function, isMultiple(), that takes two long values, n and m, and returns true if
and only if n is multiple of m, that is, n=m*i for some integer i.
7. Write a short C++ function, isTwoPower(), that takes and int i and returns true if and only if i is a
power of 2. Do not use multiplication or division, however.

Instructor: Dr. Truong Quang Vinh


Ho Chi Minh City University of Technology Department of Electronics and Electrical
Engineering

8. Write a short C++ function that takes an integer n and returns the sum of all the integers smaller
than n.
9. a) Declare the class STUDENT, which has the following members:
string ID;
string name;
unsigned int birthyear;

b) Write a constructor to assign the default values for ID, name, and birthyear;
ID = “0000”;
Name = “NO NAME”;
Birthyear = “0000”;
c) Write the overloading operator == to compare two students A and B, and return a bool value.
In this operator, each member of the class STUDENT is compared with each other.

d) Write the overloading operator = to assign copy the content of the class student A to the class
student B.

Instructor: Dr. Truong Quang Vinh

You might also like