EET 2350 Homework #2: Technical Programming Concepts and Code Examples

Verified

Added on  2022/10/01

|8
|1011
|31
Homework Assignment
AI Summary
This document provides a detailed solution to Homework #2 for the EET 2350 Technical Programming course. The solution addresses several key concepts, including the differences between char, string, array, and matrix data types, and explains their importance. It also defines structured programming and its relevance to the course. The solution further clarifies the use of 'IF', 'IF...ELSE', and 'SWITCH' statements with code examples, explains critical rules for keywords, and demonstrates increment and decrement operators with examples. Finally, it explains the modulus operator and its application in distinguishing even and odd numbers. The assignment also required the creation of two C programs: one to print the last three letters of a name using width specifications, and another using nested loops to generate a unique shape. References are included.
Document Page
Running head: TECHNICAL PROGRAMMING
Technical Programming
Name of the Student
Name of the University
Author Note
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
1TECHNICAL PROGRAMMING
Explain the differences between char, string, array and matrix. Why are these important?
Ans. Char- is a primitive data type in C that is pre-defined in the library function. It holds a
single character. It can be a letter, number, symbol or anything. For example, ‘A’, ‘8’ or ‘*’ are
treated as characters in C. To declare a character variable in C we have to write char ‘Z’ in single
codes.
String- In C language, string represents a combination of characters. it can hold multiple
characters at a time. It is declared within double codes, unlike char. For example, to declare a
string in C we have to write char *place = “Paris”.
Array- is a one dimensional data structure in C. It can store multiple values but of the same
data type. To declare an array in C we have to mention the type of data in the array, name the
array and finally write the storage capacity in closed brackets. For example, int arr[25]; where int
is the integer data type, arr is the name of the array and 25 is the memory allocation.
Matrix- Unlike array, matrices are two dimensional data structures comprising of rows and
columns. It can hold values in tabular form and can transform data. To declare matrices in C we
have to write the type of the values, the name of the array and the storage capacity of the rows
and columns. For example, int arr[5][10] is a two dimensional matrix.
What is a structured program and how does it relate to this class?
Ans. Structured programs are those that comprises of loops, sequences and decisions. Popularly
known as modular programming, it enables the user to understand and modify the program more
efficiently (Hsu and Hwang, 2017). A logical program structure is implemented through
Document Page
2TECHNICAL PROGRAMMING
structured programming. It is also considered as a subset of procedural programming. Different
modules are integrated together to form a structured program. Similarly, class is also a collection
of objects that are integrated together to perform a set of operations. Hence, the structured
programs gave birth to the concept of class in object oriented programming languages.
Explain when you would use a) “IF”, b) “IF…ELSE”, or c) SWITCH
Give examples of each with code
Ans. We can use the ‘If’ statement in C when there is a condition of either true or false. When
it’s a decision making situation, we use the if-else block. One of the conditions are written in the
if block while the other condition is written in the else block. For example,
If(a>b)
{
Max=a;
}
Else
{
Max=b;
}
We use the if-else-if statement when there are more than two conditions.
Document Page
3TECHNICAL PROGRAMMING
For example,
if(i=1)
{
printf("the sky is blue");
}
else if(i=2)
{
printf("the grass is green");
}
else
{
printf("the blood is red");
}
We can use switch case when we compare a single value or switch with all the cases and execute
only that particular case which matches with the switch. Fpr example,
switch( j)
{
case 1:
Block-1;
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
4TECHNICAL PROGRAMMING
Break;
case 2:
Block-2;
Break;
................
................
case n:
Block-n;
Break;
default:
Block-1;
Break;
}
What are the critical rules for keywords?
Ans. Keywords are pre-defined words that are stored in the library files of C. A compiler is
already aware of the function of these words; hence, we can use it in our C programs without
defining it. Since they are already reserved, we cannot use them to as variables in our programs.
Document Page
5TECHNICAL PROGRAMMING
Explain increment and decrement operators and give examples in code
Ans. Increment operators are used to increase the value of a variable. For example, i=10;
i++;
This will increase the value of i to 11.
Decrement operators are used to increase the value of a variable. For example, i=10;
i--;
This will increase the value of i to 9.
Explain modulus and give an example how it would distinguish “even” numbers from “odd”
numbers in a sort
Ans. The modulus operator is used to extract the remainder on dividing a number (Rebhi, 2017).
By dividing a certain number by 2, when the remainder left is 0, we can conclude that the
number is even. If the remainder on division is 1, the number is odd.
int num;
if (num%2==0)
{
printf("the number is even");
}
else
Document Page
6TECHNICAL PROGRAMMING
{
printf("the number is odd");
}
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
7TECHNICAL PROGRAMMING
References
Hsu, T.C. and Hwang, G.J., 2017. Effects of a structured resource-based web issue-quest
approach on students’ learning performances in computer programming courses. Journal of
Educational Technology & Society, 20(3), pp.82-94.
Rebhi, S., 2017. Equivalence of K-Functionals and Modulus of Smoothness Generated by the
Weinstein Operator. International Journal of Mathematical Analysis, 11(7), pp.337-345.
chevron_up_icon
1 out of 8
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]