Midterm-Spring2023 (1)
.docx
keyboard_arrow_up
School
Louisiana State University *
*We aren’t endorsed by this school
Course
2060
Subject
Industrial Engineering
Date
Dec 6, 2023
Type
docx
Pages
5
Uploaded by miniflassy
IE 2060 MIDTERM
Thursday, March 10, 2023
Name:
CHEATING IN ANY FORM WILL NOT BE TOLERATED AND IS
PARTICULARLY PROBLEMATIC FOR STUDENTS STUDYING TO BE
PROFESSIONAL ENGINEERS. ANY CHEATING INCIDENT WILL BE
REFERRED DIRECTLY TO THE COE DEAN AND DEAN OF STUDENTS
JUDICIAL OFFICE FOR FURTHER ACTION.
1.
[5pts] A computer has two Quadcore CPU's.
How many separate program threads can the
computer run? (
choose one only)
a.
1
b.
2
c.
4
d.
6
e.
8
f.
16
g.
32
2.
[9pts] Convert 1011011101
2
to Base 16. Show work.
733
2DD
Base 2 to decimal calculation:
(1011011101)
2
= (1 × 2
9
) + (0 × 2
8
) + (1 × 2
7
) + (1 × 2
6
) + (0 × 2
5
) + (1 × 2
4
)
+ (1 × 2
3
) + (1 × 2
2
) + (0 × 2
1
) + (1 × 2
0
) = (733)
10
Decimal to base 16 calculation:
Divide by the base to get the digits from the remainders:
Division
Quotient
Remainder
(Digit)
Digit #
733/16
45
13
0
45/16
2
13
1
2/16
0
2
2
= (2DD)
16
3.
[5pts] I wish to represent the inventory level of each product in inventory.
Due to use of lean
methods, there is never more than 1000 units of any product in inventory. Which is the "best"
C# data type to use for this?
(choose one only
)
a.
Decimal
b.
Int64
c.
UInt16
d.
String
e.
Double
f.
None of the above
4.
[7pts] Write a C# variable declaration statement for an integer variable D that also assigns it an
initial value of 48.
int D = 48;
5.
[9pts] Given the following Python code, what is the resulting value assigned to X? (specify to 2
decimal places; show intermediate results to be eligible for partial credit)
A = 4.8
B = 8.0
X = A*2-B%3+6/A
8.85
6.
[5pts] In cell C4 in Excel, I enter the formula "=Sum(A$5:D10)".
I then copy the formula to
cell E2. What will the formula be in cell E2? (
choose one only
)
a.
=Sum(C3:D10)
b.
=Sum(A$5:D10)
c.
=Sum(C$5:F8)
d.
=Sum(C$7:F12)
e.
None of the above
7.
[5pts] String variable S is equal to "AXSD4T4N".
I want to know the character position of the
last "4" in the string.
Which C# expression should I use? (
choose one only
)
a.
String.Parse(S)
b.
S.Replace("4")
c.
S.IndexOf("4",0)
d.
String.Search(S,4)
e.
S.LastIndexOf("4")
f.
S.Insert("4",7)
8.
[10pts] Double variable RH is equal to values between 0.0 and 1.0, while datetime variable D
contains the current date/time.
Write a C# statement using String.Format to format the values of
these variables into a string value like "The relative humidity is 78.3% as of 3:37pm" and assign
it to a string variable S.
double RH = 0.783;
DateTime D = DateTime.Now;
string S = String.Format("The relative humidity is {0:P1} as of {1:t}", RH, D);
9.
[5pts] Given the following function and main() code, what is written out to the console? (
choose
one only
)
static int
Q11
(
int
A,
ref int
B,
int
C
= 3)
{
A
+=
10;
B *
=
C
;
return
A*C
;
}
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
In static void Main(…):
int
M
=
8,
N
=
-1
,
P
;
P
=
Q11(M,
ref
N
);
Console.WriteLine("{0}, {1}, {2}",M,N,P);
a.
"4, 6, 8"
b.
"2, 1, 0"
c.
"8, -3, 54"
d.
"8, -1, 0"
10. [8pts] D is a datetime variable. Write the C# statement needed to subtract 4.25 days from its
current value and store the result back in D.
D = D.AddDays(-4.25);
11. [5pts] The following code is a valid polymorphic function definition ( TRUE / FALSE )
public double Q11 ( int X ) { return -X; }
public double Q11 ( int A ) { return -A; }
FALSE
12. [12pts] Write a C# public-scope function that, passed four double valued arguments A, B, C, and
X, returns the quadratic formula value = AX
2
+ BX + C.
public double QuadraticFormula(double A, double B, double C, double X)
{
double value = A * X * X + B * X + C;
return value;
}
13. [15pts] Write the C# or Python code to read in a comma separated string of names from the user
console (e.g., "Garrett, Marissa, Ben"), separate into individual names, and then add the length
of each name (removing any leading/trailing spaces) to a variable Sum.
Any name containing a
"t" (upper or lower case) should not be included in the sum. Print the value of Sum at the end of
your code.
using System;
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter comma separated names:");
string namesInput = Console.ReadLine();
string[] names = namesInput.Split(',');
int sum = 0;
foreach (string name in names)
{
string trimmedName = name.Trim();
if (!trimmedName.ToLower().Contains("t"))
{
sum += trimmedName.Length;
}
}
Console.WriteLine("The sum of lengths of names not containing 't' is: {0}", sum);
}
}
Python
names_input = input("Enter comma separated names: ")
names = names_input.split(',')
sum = 0
for name in names:
trimmed_name = name.strip()
if 't' not in trimmed_name.lower():
sum += len(trimmed_name)
print("The sum of lengths of names not containing 't' is:", sum)