CSCI 152 Spring 2015 Exam 2: C Programming Language
- Duration: 50 minutes
- Allowed to use computers, calculator, open notes, NO CELL PHONES
- Send completed program to yanako@cs.widener.edu
Choose your option
Option 1(100 points)
Write the following functions:
- int count_plus(). This function reads a sequence of characters. First '*' terminates the input.
The function counts
and returns the number of '+' signs among the input.
- void printAscii(char ch). This function has one character parameter, ch. The function prints the
character on one
line the number of
times that equals to the ASCII of char % 10.
For example, if ch is 'A' the function prints
'A' 5 times, since ASCII of 'A' is 65 and 65%10 is 5.
And if the ch is 'd', nothing will be printed,
since ASCII of 'd'
is
100 and 100%10 is 0.
Pay attention, you don't need to know ASCII values, your program should
take care of the conversion from char to int.
- Write main that reads one integer, choice.
If the choice is 1, the program calls function count_plus and outputs the result.
If the
choice is 2, program reads one char and calls function printAscii to perform the task.
If the choice is not 1 and not 2,
program randomly
generates an array of 10 integers, each integer between -5 and 5 and finds the number of elements that
equals 0 in the
array.
USE SWITCH STATEMENT
Option 2(100 points): - with Arrays - challenging
For short-term investors who plan to buy, fix up and sell their properties right away, usually the
following the after-repair-value
formula is used:
purchase_price = 75% * (after_repair_value) - repair_expenses
In this formula, after_repair_value is the price that you can sell your home AFTER it is all fixed up.
Example:
You see an older home on the market that is visibly rundown and needs repair, and the current market price
is:
$160,000 "as is." After you
assess the damage, you estimate it will require $25,000 repair expenses. Homes of the same size in the
neighborhood have been selling for $220,000 (after repair value) in "move-in, turn-key condition." You
would need to buy the
home for $140,000 or less to make it
a worthwhile investment. (75 percent of $220,000 = $165,000. $165,000 minus $25,000 = $140,000.) It means
that $160,000 is
NOT a worthwhile investment.
In this program you will store all data in 3 arrays of double values.
First array, double arv[SIZE] will hold After Repair Value for each house, second array, double re[SIZE]
will hold Repair Expenses for each
house, and third array, double market[SIZE] will hold current market price for each house.
- Write a
function
double purchase_price(double after_repair_value, double repair_expenses) that has 2 parameters:
- after_repair_value, is the price that you can sell your home AFTER it is all fixed up
- repair_expenses - amount of dollars to repair the house
The function will use the
the formula written below to calculate the purchase price:
purchase_price = 75% * (after_repair_value) - repair_expenses
The function returns the purchase price
- Write a function int process(double arv[], double re[], double market[], int real_size), where size
is the number of houses the customer
consider for purchasing, arv -
after repair value for each house, re - repair expenses for each house, and market - the current market
price for each house.
The function then calls function purchase_price to calculate the price that investor should pay for the
house to make it worthwhile
investment.
The function returns the number of houses that worthwhile investment. FOR TESTING PURPOSES, PRINT the
purchasing price for EACH house
that was calculated by function purchase_price
- Write main program that randomly generates the number of houses customer cosider for investment,
assume that the
size is between 3 and 15. Then populate 3 double arrays, arv, re, and market from user input (don't make
it random, it will be hard to test if
you will do random data).
Call function process to find the number of houses that worthwhile an investment.