Homework 2 in ENEE 114: Programming Concepts for Engineers at University of Maryland - Pro, Assignments of Electrical and Electronics Engineering

The instructions for homework 2 in the enee 114: programming concepts for engineers course at the university of maryland. The assignment covers compound conditional statements, loops, arrays, and text strings in c programming. Students are required to write programs to meet specifications and submit both the c program and a log file.

Typology: Assignments

Pre 2010

Uploaded on 07/30/2009

koofers-user-a82
koofers-user-a82 🇺🇸

9 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Electrical Engineering Department
University of Maryland at College Park
ENEE 114: Programming Concepts for Engineers
Fall 1999, Lecturer: Bill Hawkins
Homework #2, due Friday, September 24, 1999, 11:59pm.
Please refer to the handout on Handout 1, “Code of Academic Integrity and Electronic Submission” for
regulations and details for electronic submission. All section numbers in this assignment refer to The
Indispensable Guide to C.
Objectives
The specific objectives of this homework assignment are to help you learn more about the following:
Compound conditional statements that use logical operators (Section 1.6)
Simple Loops (Section 1.7)
Arrays (Section 1.8)
Text Strings (Section 1.9)
You should visualize your program through diagrams first, before attempting to write the program. Although
you do not have to hand in your diagrams for this assignment, you will save yourself lots of time writing and
debugging your program if you do so.
You MUST use the filename provided. You will lose 2 points per file that uses the wrong filename!
Question1
Design and implement a program called hw2qp.c that meets the following specifications:
Read two integers from the user, call them P and Q. Inform the user which of them is larger, e.g. print “P is
larger” or “Q is larger” or possibly “P equals Q!”
Calculate and print the sum of the integers in the range 0..P. Then do the same for Q. (Example: for P=4 the
sum(0..P) = 10.)
For each p in the range 0..P and q in the range 0..Q, calculate sum(0..p)+sum(0..q). If the result is an
integer power of 2, print p,q and sum(0..p)+sum(0..q). (Example P=4, Q=3 will print solutions p,q,sum()
of 1,2,4; 2,1,4; 4,3,16.
Submit both the C program and a log which records program compiling and execution.
To create the log, do the following once your program is working and you are ready to submit: (you type in
whatever is written in bold).
% script hw2pq.log
Script started. File is hw2pq.log
% whoami;date
[username and date printed here]
% gcc -Wall -o hw2pq hw2pq.c
% hw2pq
Enter P and Q: 3 20
...[output of your program goes here]
% hw2pq
Enter P and Q: 15 10
...[output of your program goes here]
% hw2pq
Enter P and Q: 15 10
...[output of your program goes here]
% exit
Script done, file is hw2pq.log
Submit both your C program file hw2qp.c and the log file hw2qp.log.
Hint: Start with a basic design and program that only reads the numbers and does the counting. When that
works, expand your design to include the other options, then update your program accordingly
pf2

Partial preview of the text

Download Homework 2 in ENEE 114: Programming Concepts for Engineers at University of Maryland - Pro and more Assignments Electrical and Electronics Engineering in PDF only on Docsity!

Electrical Engineering Department

University of Maryland at College Park

ENEE 114: Programming Concepts for Engineers

Fall 1999, Lecturer: Bill Hawkins

Homework #2, due Friday, September 24, 1999, 11:59pm.

Please refer to the handout on Handout 1, “Code of Academic Integrity and Electronic Submission” for

regulations and details for electronic submission. All section numbers in this assignment refer to The

Indispensable Guide to C.

Objectives

The specific objectives of this homework assignment are to help you learn more about the following:

• Compound conditional statements that use logical operators (Section 1.6)

• Simple Loops (Section 1.7)

• Arrays (Section 1.8)

• Text Strings (Section 1.9)

You should visualize your program through diagrams first, before attempting to write the program. Although

you do not have to hand in your diagrams for this assignment, you will save yourself lots of time writing and

debugging your program if you do so.

You MUST use the filename provided. You will lose 2 points per file that uses the wrong filename!

Question 1

Design and implement a program called hw2qp.c that meets the following specifications:

• Read two integers from the user, call them P and Q. Inform the user which of them is larger, e.g. print “P is

larger” or “Q is larger” or possibly “P equals Q!”

• Calculate and print the sum of the integers in the range 0..P. Then do the same for Q. (Example: for P=4 the

sum(0..P) = 10.)

• For each p in the range 0..P and q in the range 0..Q, calculate sum(0..p)+sum(0..q). If the result is an

integer power of 2, print p,q and sum(0..p)+sum(0..q). (Example P=4, Q=3 will print solutions p,q,sum()

of 1,2,4; 2,1,4; 4,3,16.

Submit both the C program and a log which records program compiling and execution.

To create the log, do the following once your program is working and you are ready to submit: (you type in

whatever is written in bold ).

% script hw2pq.log Script started. File is hw2pq.log % whoami;date [username and date printed here] % gcc -Wall -o hw2pq hw2pq.c % hw2pq Enter P and Q: 3 20 ...[output of your program goes here] % hw2pq Enter P and Q: 15 10 ...[output of your program goes here] % hw2pq Enter P and Q: 15 10 ...[output of your program goes here] % exit Script done, file is hw2pq.log

Submit both your C program file hw2qp.c and the log file hw2qp.log.

Hint: Start with a basic design and program that only reads the numbers and does the counting. When that

works, expand your design to include the other options, then update your program accordingly

Question 2

Design and implement a program hw2gr.c that will let you input student scores on an exam, edit the list of scores,

then calculate and print the maximum, minium, mean and average score for the exam along with the entire exam record.

The user interface for this program is as follows: when the program prints the prompt ‘Action:’, the user responds

with one of the following single-letter (plus arguments, in some cases) commands:

  • a <some score 0-100> //add new record; user is notified of any format failures or other input errors.
  • l //lists records in the format <line#> Last, First,Score
  • d<line#> //display one record in the above format, then prompt for a replacement on the next line. (Note: an ‘empty’ replacement value (user just hits ) aborts the edit.
  • p //print the entire list in same format as ‘d’ comand, plus the summary statistics.
  • q //quit the program.
  • h //help: print a ‘help’ screen similar to this description (but better!).

You must compile your program with all warnings enabled (use the –Wall option), and electronically submit both

the C program and a log which shows the program compilation and execution.

To create the log, do the following once your program is working and you are ready to submit: % script hw2gr.log Script started. File is hw2gr.log % whoami;date [username and date printed here] % gcc –Wall -o hw2gr hw2gr.c % hw2gr [user ‘hello’ and help instructions ouput displayed here] Action: a Donald Duck 34 Action: a Minnie Mouse 88 Action: l 1 Duck, Donald, 34 2 Mouse, Minnie, 88 Action: q % exit Script done, file is hw2gr.log

Submit both your C program file hw2gr.c and the log file hw2gr.log.

Hint: You will need to use all of the following for this question: arrays, text strings, loops, if-then statements.

–– End of Homework 2 ––