2) Short coding questions: a Write the declaration for a struct called pythType
ID: 3728258 • Letter: 2
Question
2) Short coding questions: a Write the declaration for a struct called pythType that holds 3 integers named numi, num2 and num3. b) Based on a), write the declaration for an array called pythNumber that holds 12 elements and each element's data type is pythType. c) Based on a) and b), write the function prototype, header and body for a function called checkPyth. It takes pythNumber as a parameter and checks to see if there exists an element which is a Pythagorean triple. Three numbers are a Pythagorean triple if they can be the lengths of the sides of a right triangle. That is, if the numbers are a, b and e then the numbers are a Pythagorean tripe if the following holds: a +bc This function returns true if there exists an element which is a Pythagorean triple, and false otherwise. 3) Short question: ure called SubSysteminfoBits that holds three fields named Write the declaration for a struct system_on in bit O, system_state in bit 1-7, system_error with 8 bits, which are all type of unsigned char. Write the declaration for a union called SubSysteminfo that holds two fields named infoAsBits typed of SubSysteminfoBits and inforAsWord typed of unsigned short. How much memory is allocated to a variable of type SubSysteminfoBits and a variable of type SubSysteminfo respectively? a) b) c) Recursion: Given an integer n>o, write a recursive C++ function that returns the sum of 1 through n. What output does the following program produce? int getValue(int a, int b, int n); 1. 2. int main() coutccgetValue(1,7,7kcendl; return 0; int getValue(int a, int b, int n)Explanation / Answer
2.a.
struct pythType
{
int num1;
int num2;
int num3;
};
2.b.
struct pythType pythNumber[12];
2.c
bool checkPyth(struct pythType pythNum[])
{
for(int i =0; i<12; i++) //as specified above it contains 12 elements
{
if(pow(pythNum[i].num1,2)+pow(pythNum[i].num2,2) = pow(pythNum[i].num3,2))
{
return true;
}
}
return false;
}
3.a.
struct SubSystemInfoBits
{
unsigned char system_on: 0;
unsigned char system_state:7;
unsigned char system_error:8;
};
3.b.
union SubSystemInfo
{
SubSystemInfoBits infoAsBits;
unsigned short infoAsWord: 16;
};
3.c.
memory for SubSystemInfoBits is equal to sum of size of all data memeber. In case of union memory is always equal to memory required by largest member in the union.
Recursion:
1.
void sumofN(int n)
{
if (n <= 1)
return n;
return n + sumofN(n - 1);
}
2. getvalue is not visible and cannot be able to answer.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.