首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
EP3BB3编程代写、C++程序设计代做
项目预算:
开发周期:
发布时间:
要求地区:
EP3BB3 Lab #1-2024/25-V1.3
Lab 1: Introduction to C Programming
1 Introduction
This lab serves as an introduction to C programming language for those who may be new to it, and a
refresher for those familiar with it. The aim is not an in-depth exploration of C but a review of the basics
through exercises to ensure your readiness for its applications in the upcoming labs.
1.1 Software Installation
In case you haven’t done so already, install Visual Studio Code and C using the instructions provided on
Avenue to Learn. Please note that this step is time consuming and therefore, you should do this ahead
of your lab.
1.2 Hello World!
To ensure that you have set up Visual Studio Code correctly, open Visual Studio Code and create a New
File. Name it as you want as file_name.c. Copy the following code:
#include
int main(void){
printf("Hello World!");
return 0;
}
Then use the icon “Debug C/C++ File” from the top right corner of the page (see the image below). You
should see the phrase “Hello World” in the terminal window. Now that we confirmed everything works,
let’s get to the lab!
EP3BB3 Lab #1-2024/25-V1.3
2
2 Lab 1 – The Real Thing
In this lab, we will have different exercises with a strong focus and emphasis on binary and bitwise
operations as these will be an essential concept throughout this semester.
2.1 Sample Program
Recommended duration for task completion: 10 minutes
Recall this program from your lecture notes which reads three integer values from the user and prints the
average. Let’s quickly review this program:
#include
int main(void)
{
int value1, value2, value3;
float sum, average;
printf("What is the first value? ");
scanf("%d", &value1);
printf("What is the second value? ");
scanf("%d", &value2);
printf("What is the third value? ");
scanf("%d", &value3);
sum = value1 + value2 + value3;
average = sum / 3;
printf("The average of %d, %d, and %d is %f\n", value1, value2, value3,
average);
return 0;
}
We will be using this example to introduce debuggers! Debuggers help you inspect different portions of
the code and understand how different variables change as the program runs. You can add “Breakpoints”
to force your code to pause when it reaches certain points. To enable breakpoints for different lines, you
can simply click in the area next to the line number (see below). EP3BB3 Lab #1-2024/25-V1.3
3
In the example above, we have added two breakpoints in lines 17 and 18. When you run the code by
pressing Debug C/C++ File, an icon bar appears on the top of screen and when it reaches the breakpoint,
it will look similar to the image below. Visit this page and review the “Debug actions” table to learn more
about these icons.
Now, the values for different variables before calculations of lines 17 and 18 are listed on the left side of
your screen (see below, picture “a”). When you press “Step Over” from the icon bar above, the values will
be updated (see below, picture “b”).
In addition, after running the debugger, you can right click on any variable in your code and select “Add
to Watch” to inspect that variable.
Task #2.1: Use the debugger yourself and explain the program above to your TA line by line.
(a) (b) EP3BB3 Lab #1-2024/25-V1.3
4
2.2 if-else Conditional Statements
Recommended duration for task completion: 20 minutes
Task #2.2: Write a program that reads a non-zero number from the user and determines if it is even or
odd. Explain the program to your TA line by line.
#include
int main(void)
{
// Declare an integer.
printf("Please enter a non-zero number: ");
// read the number from the user using scanf.
// In the following if statement, determine if the number is divisible by 2
using the modulo operator.
/*
if (CONDITION) {
// Print the entered number is even/odd. You must show the number entered
by the user.
}
else {
// Print the entered number is odd/even. You must show the number entered
by the user.
}
*/
return 0;
}
EP3BB3 Lab #1-2024/25-V1.3
5
2.3 While Loops
Recommended duration for task completion: 20 minutes
Task #2.3: Write a program, using while loops, that writes numbers from 1 to 10. Explain the program to
your TA line by line.
#include
int main(void){
// Declare an integer here and initialize it with a reasonable value.
// The while loop (below) prints the integer and then increments it, as long
as it satisfies the CONDITION.
// while (CONDITION) {
// Print the integer.
// Increment the integer.
}
return 0;
} EP3BB3 Lab #1-2024/25-V1.3
6
2.4 For Loops
Recommended duration for task completion: 20 minutes
Task #2.4: Write a program, using for loops, that prints all the even numbers between 1 to 10. Explain the
program to your TA line by line.
#include
int main(void){
// Declare an integer.
//The for loop (below) should go through the numbers from 0 to 10 and check
if the number is divisible by 2.
//for (start from 0 and increment until 10){
/*if (divisible by 2, for example using the modulo operator){
// Print the value.
}
else
{
// Don't do anything.
}*/
}
return 0;
}
EP3BB3 Lab #1-2024/25-V1.3
7
2.5 User-Defined Functions
Recommended duration for task completion: 20 minutes
Task #2.5: Rewrite the sample program of task 2.1. Once the user inputs three integers, pass them to
another function called averageCalculator, which calculates the average and returns the value to the main
function. The main function, then, prints the calculated average value. Explain the program to your TA line
by line.
#include
float averageCalculator (int a, int b, int c);
float average;
int main(void)
{
int value1, value2, value3;
printf("What is the first value? ");
scanf("%d", &value1);
printf("What is the second value? ");
scanf("%d", &value2);
printf("What is the third value? ");
scanf("%d", &value3);
// Call the averageCalculator function and pass the values.
printf("The average of %d, %d, and %d is %f\n", value1, value2, value3,
average);
return 0;
}
// Define a function name averageCalculator which reads three integers (as
arguments) and returns the parameter average as a float.
/*
return_type averageCalculator(arguments)
{
Do the calculations here and return the average!
}
*/
EP3BB3 Lab #1-2024/25-V1.3
8
3 Bitwise operations
Due to the importance of bitwise operations in the future labs, we will now work on some exercises
related to this topic.
3.1 Exercise 3.1
Recommended duration for task completion: 30 minutes
Task #3.1: Study and complete the following code. In this code, the user enters two decimal numbers. The
code will calculate different bitwise operations and prints the results represented in decimal. For example,
take a value of 7 for a (0000 0111 in binary) and a value of 12 for b (0000 1100 in binary). A bitwise AND
of these values is 4 represented in decimal which is 0000 0100 in binary. Complete the code, use a
different set of input number, and show that your results from your on-paper calculations and those
derived from your code match.
#include
int main(void)
{
int a, b;
printf("What is the first value (in decimal)? ");
scanf("%d", &a);
printf("What is the second value (in decimal)? ");
scanf("%d", &b);
printf("The bitwise AND of %d, and %d, REPRESENTED IN DECIMAL, is %d\n", a,
b, a & b);
// Print the bitwise OR of the two numbers.
// Print the bitwise XOR of the two numbers.
// Print the bitwise NOT of one of the numbers.
// Print the bitwise left shift (shifted by one bit) of one of the numbers.
// Print the bitwise right shift (shifted by one bit) of one of the numbers.
return 0;
}
EP3BB3 Lab #1-2024/25-V1.3
9
3.2 Exercise 3.2
Recommended duration for task completion: 30 minutes
Imagine you are in a room which has 8 LED light switches controlling 8 different LED lights. Of course, at
any given time, each light can be either on or off. The goal is to independently control these LEDs without
unintentionally affecting the others. Maybe you want to turn on (or SET) specific LEDs. Maybe you want
to turn off (or CLEAR) some or all of them. Maybe, and maybe, you want to flip (or TOGGLE) specific ones.
Or perhaps, you want to play a prank on your roommate by flipping all the switches, turning on what’s off
and turning off what’s on (INVERT).
LED 7 LED 6 LED 5 LED 4 LED 3 LED 2 LED 1 LED 0
OFF OFF ON OFF ON OFF ON ON
Well, as it turns out, this is what your microcontroller looks like. For instance, PORT1 of your
microcontroller has 8 pins (labeled from 0 to 7). Let’s do ourselves a favor and consider them a binary
sequence. Each pin can have a value of 0 or 1 (i.e., binary). In these cases, it is important to know the
current state of the system as well as the change you want to impose on the system. You can then
calculate the final state of the system using the bitwise assignment operators. These are basically the
same bitwise operators from Exercise 3.1, however they are now followed by the assignment “=” sign. So,
what’s the difference?
The bitwise AND assignment (&=) first calculates the bitwise AND operation between operands and then
assigns the value to the left operand. It can be used to clear bits.
The bitwise OR assignment (|=) first calculates the bitwise OR operation between operands and then
assigns the value to the left operand. It can be used to set bits.
The bitwise XOR assignment (^=) first calculates the bitwise XOR operation between operands and then
assigns the value to the left operand. It can be used to toggle bits.
Lastly, the operation ~ can be used to invert bits: turning all ones to zeros and vice versa.
Let’s work through an example. Imagine the initial state of the system of LEDs in the table above is 0010
1011 (equivalent to 43 in decimal), where each bit represents the state of a specific pin, with 0 and 1
indicating states such as ON/OFF. Now, let’s say you want to turn off all LEDs except the 6th bit (or LED #5)
i.e., 0010 0000 (or 32 in decimal). You can CLEAR using the bitwise AND assignment operation (&=). Use
the following code for a practical demonstration.
Task #3.2: After making this observation, complete the code below to calculate the bitwise OR assignment
and the bitwise XOR assignments for a different set of input states (initial state and change). Show that
your results from your on-paper calculations and those derived from your code match. More importantly,
explain how these different operations can be used to set/clear/toggle/invert bits.
EP3BB3 Lab #1-2024/25-V1.3
10
#include
int main(void)
{
int initialstate, change, tempstate;
printf("What is the initial state (in decimal)? ");
scanf("%d", &initialstate);
tempstate = initialstate;
printf("What is the change (in decimal)? ");
scanf("%d", &change);
initialstate &= change;
printf("The &= of %d, and %d is %d\n", tempstate, change, initialstate);
return 0;
}
EP3BB3 Lab #1-2024/25-V1.3
4 Code Submission
Codes for all tasks must be submitted before the deadline (Jan 12th, 2025 by 7:30 PM EST) on Avenue to
Learn.
EP3BB3 Lab #1-2024/25-V1.3
5 What’s Next?
5.1 Assessment and Reflection on the Lab
Spend a few minutes and reflect on what you learned today. Your TAs will assess your lab based on your
understanding and explanation of what you have done, observed, and learned during this lab (and the
pre-lab when applicable). Explain the technical details to your TAs and share your takeaways of the lab.
Half of your mark for the lab is dedicated to your code and its functionality and the other half to your
understanding and explanations.
Even though you are working in groups of 2, you are expected to write your own codes and do each tasks
individually. However, you are encouraged to discuss your approach with your lab partner.
5.2 Tidying Up
Firstly, great work finishing your lab! You can leave the lab after cleaning your workstation:
• Remove the jumper wires from your breadboard and dump them in the wire containers on your
workstation.
• Remove the components from your breadboard and place them in the component containers at
your workstation. Make sure to put the components back in the right drawers.
• Disconnect the probes from your power supply, function generator, multimeter, and oscilloscope,
and hang them from the wire rack on the wall.
• Remove any pieces of paper, garbage, etc., from and clean your workstation before leaving the
lab.
Note: You are always expected to clean your workstation before leaving the lab.
5.3 Next Lab’s Preparation
The lab manual for the next lab on “Introduction to Microcontrollers” is available on Avenue to Learn.
Please review the lab manual before attending the lab. In particular:
• Follow the instructions published on Avenue to Learn to purchase the microcontroller and bring
your microcontroller to the lab.
• Before coming to the lab, you must review the prelab and follow the instructions to install
CCSTUDIO — Code Composer Studio™ integrated development environment (IDE). This should be
done before coming to the lab.
• After installing the IDE, follow the prelab’s blink test to make sure everything is set properly.
软件开发、广告设计客服
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-23:00
微信:codinghelp
热点项目
更多
代做mime 473 – winter 2025 ...
2025-02-20
代写cit 5960 2025 - hw4代写留...
2025-02-20
代做econ 440.602: macroecono...
2025-02-20
代写phas0008 experimental me...
2025-02-20
代做emet4314/8014 advanced e...
2025-02-20
代写project 4: composition p...
2025-02-20
代写st332 & st409 medica...
2025-02-20
代写comp212 - 2025 - ca assi...
2025-02-20
代写construction specialisat...
2025-02-20
代做ma dcs 7aavdc29 practica...
2025-02-20
代做cs 4293 topics on cybers...
2025-02-20
代写as.440.601 microeconomic...
2025-02-20
代做project 3: composition p...
2025-02-20
热点标签
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
- QQ: 9951568
© 2021
www.rj363.com
软件定制开发网!