Midterm 1 Solutions - Introduction to C Programming | CS 102, Exams of Computer Science

Material Type: Exam; Professor: Kolimi; Class: INTRO TO C PROGRAMMING; Subject: Computer Science; University: University of Alabama - Huntsville; Term: Spring 2011;

Typology: Exams

2010/2011

Uploaded on 05/02/2011

hirotaka27
hirotaka27 🇺🇸

1 document

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 102-04: Introduction to C programming
Kolimi
Midterm1
Date: 22nd February 2011
Student Name:
Instructions:
1. Please read the questions carefully. If you don’t understand any part please ask the instructor,
but do not talk to your neighbors during the exam.
2. The question1 is a definition/syntax correction problem and questions 2, 3, 4 are programming
problems.
3. Please save this copy on your desktop, write all the answers for question 1 and program the
solutions for question 2,3 and 4 in Visual studio[If you write these in Word, I cannot grade them]
and paste the executed solutions in this document. Rename this document with: your full name
on record-Mid1 and drop this document in the Midterm1 dropbox.
pf3
pf4

Partial preview of the text

Download Midterm 1 Solutions - Introduction to C Programming | CS 102 and more Exams Computer Science in PDF only on Docsity!

CS 102-04: Introduction to C programming

Kolimi

Midterm

Date: 22nd^ February 2011 Student Name:

Instructions :

  1. Please read the questions carefully. If you don’t understand any part please ask the instructor, but do not talk to your neighbors during the exam.
  2. The question1 is a definition/syntax correction problem and questions 2, 3, 4 are programming problems.
  3. Please save this copy on your desktop, write all the answers for question 1 and program the solutions for question 2,3 and 4 in Visual studio[If you write these in Word, I cannot grade them] and paste the executed solutions in this document. Rename this document with: your full name on record-Mid1 and drop this document in the Midterm1 dropbox.

Question 1: (20 points) a. What is a Programming Language? Give some examples of programming languages. b. What is an Operating system? Give some examples. c. What are various data types in C? Give the short forms you use in C. d. Define ALU and CPU. e. What is \n, why is it used in printf statement? For the next part of question1, Identify and correct the error(s) in if any, in each of the following statements: f. int number = 9; printf("The number is %d \n", &number); g. int number; scanf("%d", number); h. if( c < 7) printf(" c is less than 7 \n ); i. char vari; printf("Please enter either a or b \n"); scanf("%d", &vari); j. int a

a = 1;

Extra credit: k and j bits are extra credit. k. char choice; switch(choice) { case a: printf("you have chosen character 'a' in the menu"); break; default:printf("Sorry not a"); }

[Hint: Make use of if… else statements] [Please scroll down for the last question] Question 4: (20 points) Uses Switch case structure Write a program which prints the message: “Enter a character among c,p,t, or f where c - CBS p - PBS t - TBS f - FX” The program accepts a character input using scanf () and uses the switch…case structure. This is a part of a larger application which lets the user select TV channels. [Hint: Declare a character datatype variable for switch case and then scanf() value into this variable] When the user enters ‘c’ --- print “You have selected CBS – it’s on Channel 34” When the user enters ‘p’ --- print “You have selected PBS – it’s on Channel 29” When the user enters ‘t’ --- print “You have selected TBS – it’s on Channel 37” When the user enters ‘f’ --- print “You have selected FX – it’s on Channel 43” When the user enters something other than c, p, t, f – print “Currently not on the menu, try again later!”