Homework2_Solution
.pdf
keyboard_arrow_up
School
San Francisco State University *
*We aren’t endorsed by this school
Course
213
Subject
Computer Science
Date
Dec 6, 2023
Type
Pages
6
Uploaded by EarlBoar3947
ENGR213 Spring 2023 Homework 2 Solution Part A (40%) 1.
Determine which of the following are valid identifiers. If invalid, explain why. (5%) A.
Name and address: Blank spaces are not allowed B.
123-45-6789: An identifier must begin with a letter or an underscore 2.
Determine which of the following are valid constants. If invalid, explain why. (10%) A.
0.8E 8 –
valid integer constant? Invalid because of blank space B.
018CDF –
valid integer constant? Invalid, in hexadecimal constant there must be x (i.e., 0x18CDF) C.
‘
\
a’ –
valid character constant? Valid D.
“The professor said, “please don’t cheat in Exam” –
valid string constant? Invalid, the quotation marks and apostrophes within the string must be expressed as escape sequence (i.e., “The professor said, \
“please don\
’t cheat in Exam
\
”
”)
3.
Write appropriate declarations and assign the given initial values for each group of variables and arrays. (10%) A.
Floating-point variables: a= -8.2, b = 0.005 Integer variables: x = 129, y = 87, z = -22 Character variable: c1= ‘w’, c2 = ‘&’
B.
One-
dimensional character array: message = “ERROR”
ENGR213 Spring 2023 4.
What will be output of the following c program? 5% A. 20 B. 0 C. Compilation error D. None of these
5.
Run the following program and analysis the program output. 10% A.
What is the output of this program? Why? c1 = a, c2 = b c1 = 97, c2 = 98 The reason why the first line is printing chars even with an integer initialized to it is because %c will automatically see that as an ASCII code and finds the corresponding character. The second line only requires an integer, so the program will choose the integer version of char which is the ASCII code to print. B.
If we change the line 5, 6 to C1 = 197; C2 = 198;
What is the output of this program after you change the code? Why?
ENGR213 Spring 2023 c1 = [?], c2 = [?] c1 = -59, c2 = -58 The first printf() gives character output translated from ASCII table but there’s no corresponding character in number 197 and 198 (because the range limit is 0 to 127) it’s showing a question mark symbol instead. For the second printf(
), since c1 and c2 are declared as a char, data type char has a range limit from -128 to 127. If a positive number exceed the boundary it loops from the other end, which is -128. In this case, a positive number 128 as type char represents as -128 and 129 as -127. So 197 prints as -128+(197-127) -1 = -59; and 198 prints as -128+(198-127) -1 = -58. C.
If we change the line 4 to int c1,c2; What is the output of this program after you change the code? Why? c1 = [?], c2 = [?] c1 = 197, c2 = 198 The first printf() is the same as (2) for the same reason. The second printf() gives the number of 197 and 198 instead of negative number because c1 and c2 are declared as data type int, which has a much larger range limit than 3 digits. So the number may not loop back as a negative number as output
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Related Questions
C LANGUAGE ONLY. ANSWER ASAP.
Using the program provided below:
Add the following features that are listed below to the provided program:
Store student ID numbers and their corresponding GPAs in a structure. ID numbers should be 8 digits. (Ex. 11926743) and GPA should be (0.0, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0)
Add students
Remove students
Display the list of students
Start of code:
FILE NAME: linked_lists.h
#ifndef LINKED_LISTS_H#define LINKED_LISTS_H
struct node { int data; struct node* next;};
void insertAtBeginning(struct node** head, int data);void insertAtEnd(struct node** head, int data);void insertAfter(struct node* prev_node, int data);void deleteNode(struct node** head, int key);void swapNodes(struct node** head, int x, int y);void printList(struct node* head);
#endif
FILE NAME: linked_lists.c
#include <stdio.h>#include <stdlib.h>#include "linked_lists.h"
void insertAtBeginning(struct node** head, int data) { struct node* new_node = (struct…
arrow_forward
Computer Science
Hello! can someone provide Swift programming help with these 2 questions.
1. Create an example of the Modulo operator that prints the values 0 through 9 for any
value of positive Integer.
2. Create at least four examples of using four different Compound Assignment operators.
arrow_forward
Q1
a)for each of the following problems, choose the right data
structure to solve the problem and EXPLAIN why your answer
works better than other options :
i) Given runners' names in 1st, 2nd,..., nth places, the
announcer needs to announce the award in reversed order,
which means the first place is announced last.
ii) Trucks drive onto a toll bridge from one end and exit from
the other end of the bridge.
arrow_forward
I need the answer as soon as possible
arrow_forward
Question 16
The terms variable and identifier can always be used interchangeably.
O True
O False
arrow_forward
Programming Language :- Python
arrow_forward
Problem Description
MyKad is the compulsory identity card for Malaysian citizens aged 12 and above. The current
format of the Malaysian identity card number was introduced in 1990, features 12 digits
separated into three blocks by hyphens, as illustrated below:
YYMMDD-PB-###G
The first six digits signify the person's date of birth in the ISO 8601:2000 format; the seventh
and eighth digit, represents the place of birth of the person. The ninth through eleventh digit
is the generic special number generated by the National Registration Department of Malaysia's
computer system. G, the 12th digit represents the gender of the person. The odd number for G
denote male while the even number denote female.
For example, 2906 is female (6 is even number) and 8995 is male (5 is odd number)
You are given a list of the last 4 digits of MyKad. Write a program to calculate the number of
male and female.
Input
The input starts with X (1M F
Sample Input Output
Sample Input
5 2906 2652 8195 3441 9534…
arrow_forward
1.) Which of the following is true?a) An AIS must be computerized to be usefulb) An AIS always produces useful informationc) An AIS always produces financial informationd) none of these
2.) Which of the following is true about the terms “dataâ€and “information†within the context of Chapter 1?a) The terms are exactly the sameb) The terms are always exact oppositesc) Some “data†can also be “informationâ€d) none of these
3.) Most AISs perform all of these functions except:a) Collect raw accounting datab) Store accounting data for future usesc) Process data into useful informationd) AISs perform all of these functions
4.) Which of the following is one of the five interactingcomponents of an accounting information system?a) Fuzzy logicb) Testingc) Certificationd) Procedurese) Internet
5.) A computer network spanning regional, national, orglobal areas best describes which of the following?a) LANb) WANc) ESPNd) DSLe) ISDN
6.). Documentation includes:a) All flowcharts,…
arrow_forward
None
arrow_forward
QI) Explain with example the purpose for the use of the following operators:
1) += 2)|
3) ? :
arrow_forward
1.
Consider the following statements:
DATAENDFLAG is off; ERROR equals 0; and SUM is less than 1024. Express the following sentences
in symbolic notation:
(i)
DATAENDFLAG is off, ERROR equals 0, and SUM is less than 1024.
(ii)
(iii)
(iv)
DATAENDFLAG is off but ERROR is not equal to 0.
DATAENDFLAG is off; however, ERROR is not 0 or SUM is greater than or equal to 1024.
Either DATAENDFLAG is on or it is not the case that both ERROR equals 0 and SUM is less
than 1024.
(v)
If DATAENDFLAG is off and SUM is less than 1024, then ERROR equals 0.
arrow_forward
Help, please in C# programming language
arrow_forward
Q3) Enter this matrix and find and display the results on the command window in Matlab:
9 51
-2 3 0
3 5]
2
S =
1
1- The first row of a matrix.
2- The third column of a matrix.
3- The Inverse of a matrix.
arrow_forward
hi this my firs time i need ur help
i want to solev this proplem by uesing online java compiler
A registration officer in an academic institution wants to display the Student transcript in a given semester after entering the required student details. A student is characterized by an ID, full name, the semester in which he/she is registered and other details. The student can take from 3 to 4 modules every semester and has two assessments in each module. You are requested to write the program that will help the officer to display the indicated transcript using Classes, methods, arrays and various control statements.The following shows an example of execution of this program.Questions:a. What is the role of a normal constructor? Create the class Student, which must have a normal constructor and at least 5 attributes. Note: The attributes must include all the details mentioned in the scenario and others of your choice. The marks of the student in different modules must be stored using…
arrow_forward
: A large eCommerce company wishes to list the best-selling products, overall and bycategory. For example, one product might be the #1056th best-selling product overall but the #13thbest-selling product under "Sports Equipment" and the #24th best-selling product under "Safety:·Describe how you would design this system.
arrow_forward
p.77, icon at Example 6
#4. Determine whether this argument is valid by using a truth table:
I play golf or tennis.
If it is not Sunday, I play golf and tennis.
If it is Saturday or Sunday, then I don't play golf.
Therefore, I don't play golf.
arrow_forward
Can u please help me with these parts? because I get confused
A registration officer in an academic institution wants to display the Student transcript in a given semester after entering the required student details. A student is characterized by an ID, full name, the semester in which he/she is registered and other details. The student can take from 3 to 4 modules every semester and has two assessments in each module.
You are requested to write the program that will help the officer to display the indicated transcript using Classes, methods, arrays and various control statements. The following shows an example of execution of this program.
Questions:
What is the role of a normal constructor?
Create the class Student, which must have a normal constructor and at least 5 attributes.
Note: The attributes must include all the details mentioned in the scenario and others of your choice. The marks of the student in different modules must be stored using arrays.
Explain the benefits of…
arrow_forward
Can u please help me with these parts? because I get confused
A registration officer in an academic institution wants to display the Student transcript in a given semester after entering the required student details. A student is characterized by an ID, full name, the semester in which he/she is registered and other details. The student can take from 3 to 4 modules every semester and has two assessments in each module.
You are requested to write the program that will help the officer to display the indicated transcript using Classes, methods, arrays and various control statements. The following shows an example of execution of this program.
Questions:
What is the role of a normal constructor?
Create the class Student, which must have a normal constructor and at least 5 attributes.
Note: The attributes must include all the details mentioned in the scenario and others of your choice. The marks of the student in different modules must be stored using arrays.
2. Explain the benefits of…
arrow_forward
Q1. Identify the values and variables in the following statements.
а 3 100
Name = "Sheikha"
Q2. Identify the datatype for the following cases:
• age of
• number of birds
• name of a person
• a number which has a real and imaginary part
a
person
• Number of goals a team in football has scored
Q3. Write a statement to store the following paragraph in a variable and print the variable.
"The boy climbs the hill to fetch a pail of water and fell down"
Q4. Write a program to find the 5% discount of any product.
arrow_forward
Transcribed Image Text
A student took four quizzes in a term and would like to compute their average. He also would like to know what will be the remarks. Follow the range of grades and its equivalent remarks, and then fill-up the table below: 100-95 - Excellent 94-90 – Very Satisfactory 89-85 - Satisfactory 84-80 - Fine 79-75 - Fair 74 and below - Poor
arrow_forward
What does the data type defined by union will do? a) It allow one different portion of memory to be accessed as same data types b) It allow one same portion of memory to be accessed as same data types c) It allow one different portion of memory to be accessed as different data types d) It allow one same portion of memory to be accessed as different data types
arrow_forward
AcmeSoft company are either programmers or salespeople. The programmers always tells the truth, the salespeople always lie Two AcmeSoft employees A and B were sitting with a visitor in a conference room. A makes the following statement, “At least one of us is a salesperson." What are A and B?
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:9781337508841
Author:Carey
Publisher:Cengage
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
Related Questions
- C LANGUAGE ONLY. ANSWER ASAP. Using the program provided below: Add the following features that are listed below to the provided program: Store student ID numbers and their corresponding GPAs in a structure. ID numbers should be 8 digits. (Ex. 11926743) and GPA should be (0.0, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0) Add students Remove students Display the list of students Start of code: FILE NAME: linked_lists.h #ifndef LINKED_LISTS_H#define LINKED_LISTS_H struct node { int data; struct node* next;}; void insertAtBeginning(struct node** head, int data);void insertAtEnd(struct node** head, int data);void insertAfter(struct node* prev_node, int data);void deleteNode(struct node** head, int key);void swapNodes(struct node** head, int x, int y);void printList(struct node* head); #endif FILE NAME: linked_lists.c #include <stdio.h>#include <stdlib.h>#include "linked_lists.h" void insertAtBeginning(struct node** head, int data) { struct node* new_node = (struct…arrow_forwardComputer Science Hello! can someone provide Swift programming help with these 2 questions. 1. Create an example of the Modulo operator that prints the values 0 through 9 for any value of positive Integer. 2. Create at least four examples of using four different Compound Assignment operators.arrow_forwardQ1 a)for each of the following problems, choose the right data structure to solve the problem and EXPLAIN why your answer works better than other options : i) Given runners' names in 1st, 2nd,..., nth places, the announcer needs to announce the award in reversed order, which means the first place is announced last. ii) Trucks drive onto a toll bridge from one end and exit from the other end of the bridge.arrow_forward
- Problem Description MyKad is the compulsory identity card for Malaysian citizens aged 12 and above. The current format of the Malaysian identity card number was introduced in 1990, features 12 digits separated into three blocks by hyphens, as illustrated below: YYMMDD-PB-###G The first six digits signify the person's date of birth in the ISO 8601:2000 format; the seventh and eighth digit, represents the place of birth of the person. The ninth through eleventh digit is the generic special number generated by the National Registration Department of Malaysia's computer system. G, the 12th digit represents the gender of the person. The odd number for G denote male while the even number denote female. For example, 2906 is female (6 is even number) and 8995 is male (5 is odd number) You are given a list of the last 4 digits of MyKad. Write a program to calculate the number of male and female. Input The input starts with X (1M F Sample Input Output Sample Input 5 2906 2652 8195 3441 9534…arrow_forward1.) Which of the following is true?a) An AIS must be computerized to be usefulb) An AIS always produces useful informationc) An AIS always produces financial informationd) none of these 2.) Which of the following is true about the terms “dataâ€and “information†within the context of Chapter 1?a) The terms are exactly the sameb) The terms are always exact oppositesc) Some “data†can also be “informationâ€d) none of these 3.) Most AISs perform all of these functions except:a) Collect raw accounting datab) Store accounting data for future usesc) Process data into useful informationd) AISs perform all of these functions 4.) Which of the following is one of the five interactingcomponents of an accounting information system?a) Fuzzy logicb) Testingc) Certificationd) Procedurese) Internet 5.) A computer network spanning regional, national, orglobal areas best describes which of the following?a) LANb) WANc) ESPNd) DSLe) ISDN 6.). Documentation includes:a) All flowcharts,…arrow_forwardNonearrow_forward
- QI) Explain with example the purpose for the use of the following operators: 1) += 2)| 3) ? :arrow_forward1. Consider the following statements: DATAENDFLAG is off; ERROR equals 0; and SUM is less than 1024. Express the following sentences in symbolic notation: (i) DATAENDFLAG is off, ERROR equals 0, and SUM is less than 1024. (ii) (iii) (iv) DATAENDFLAG is off but ERROR is not equal to 0. DATAENDFLAG is off; however, ERROR is not 0 or SUM is greater than or equal to 1024. Either DATAENDFLAG is on or it is not the case that both ERROR equals 0 and SUM is less than 1024. (v) If DATAENDFLAG is off and SUM is less than 1024, then ERROR equals 0.arrow_forwardHelp, please in C# programming languagearrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Np Ms Office 365/Excel 2016 I NtermedComputer ScienceISBN:9781337508841Author:CareyPublisher:CengageC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningProgramming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:9781337508841
Author:Carey
Publisher:Cengage
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning