Lab Guide 12
Lab Guide 12
Q1. Fill in the blanks in the following C program using the given addresses and values of ptr and y variables. Then, write and
execute it on your development environment and observe if all of the output is valid or not to correct your errors;
addresses should look like hexadecimal numbers while values should look like decimal values.
#include <stdio.h>
ptr y
Value: 0055F760
*
Value: 860
int main (void) &
{
int y = 860; Address: 0055F754 Address: 0055F760
int *ptr;
ptr = &y;
printf("1.Value of the variable y by using y is : __\n", ___);
printf("2.Value of the variable y by using ptr is : __\n", ___);
*ptr = 205;
Q2. In a Car Credit system, there is a calculator for the customers that calculates monthly payment and total money amount
for a customer which wants to receive a loan for a car, according to the selected bank information.
Example Run:
Enter your credit amount: 180000 4. SEKERBANK
Enter your maturity: 60 Select one of the bank: 9
Select one of the bank: -3
MENU Select one of the bank: 3
1. Vakifbank
2. YAPI KREDI Total money you will pay is 304200.00
3. GARANTI Monthly pay is 5070.00
Q3. In a central phone company; for the 4 big cities in Turkey (Ankara, Istanbul, Izmir and Konya); new phone numbers will be
generated according to the city code and old phone numbers of a user.
Write a C program that gets city code and phone number of 3 users, then it makes the new phone and also shows the plate
code according given conditions and using the following functions.
Plate number is; 06 for city code 312 (Ankara),
Plate number is; 34 for city code 212 (Istanbul),
Plate number is; 35 for city code 232 (Izmir),
Plate number is; 42 for city code 332 (Konya),
Otherwise, assume plate number is 0.
New Phone number will be generated; plate number * city code, then it is added to the old phone number.
Your program should make data validation for the digits of the city code (312 must be 3 digit) and also phone number (290
5058 must be 7 digit).
ExampleRun:
Enter the 1. user city code and phone number:25 6394125 Project Name: LG12_Q3
File Name: Q3.cpp
Wrong city code or phone enter again!
Enter 1. user the city code and phone number:212 5653987
Q4.
a) Write a C program that reads 10 numbers from a text file named “numbers.txt”. Then, it displays these values on the
screen and calculate their multiplication.
numbers.txt
4 6 9 1 2 8 3 5 7 1 3 9 6 3 6 8 9 3 Project Name: LG12_Q4a
File Name: Q4a.cpp
Example Run:
Numbers read from the file are: 4 6 9 1 2 8 3 5 7 1
The multiplication of these numbers 362880
b) Modify the program Q4a that the file is, now, read until the end of file, instead reading a certain amount of numbers.
Example Run:
Numbers read from the file were: 4 6 9 1 2 8 3 5 7 1 3 9 6 3 6 8 9 3 Project Name: LG12_Q4b
The multiplication of these numbers were 928878592 File Name: Q4b.cpp
c) Modify the program Q4b that reads the numbers from the file “numbers.txt”. Then, writes the numbers which are even
to the even.txt, writes other numbers to the file named odd.txt.
even.txt
4 6 2 8 6 6 8
Project Name: LG12_Q4c
odd.txt File Name: Q4c.cpp
9 1 3 5 7 1 3 9 3 9 3
Q5. Write the following function;
isPerfect() that gets an integer number then decides whether an integer is perfect or not.
( A perfect number is a number whose sum of it is divisors equal to number itself excluding number itself and 1. )
Write a C program that reads a list of integers from a text file named “integers.txt” and displays the perfect numbers.
integers.txt
6 10 38 91 65 99 32 67 80 91 28 15 18 23 37 45 86 72 41 62 38 93 27 68 90 12 25 80 33 57
Example Run:
Project Name: LG12_Q5
Perfect numbers are : 6 28
File Name: Q5.cpp
Additional Questions
AQ1.
Write the following function;
convertDays() that gets the value the user gave in units of days, in order to compute and “return” the
respective values of years, months and days.
Write C program that gets a number representing an amount of days for this number in the units of days to be represented
in years, months and days respectively. Examine the example run below, carefully.
Hint: Assume that one year is 365 days, one month is 30 days.
Example Run:
Enter the number of days (-1 to stop): 3333
3333 days is 9 year(s), 1 month(s), 18 day(s)
AQ2.
Write the following functions;
convertUnits() that gets the parameters of hours, minutes, seconds and milliseconds and calculates how many
minutes, seconds and milliseconds have been passed to beat that record.
aDayLater() that gets the parameters of hours, minutes, seconds and milliseconds and calculates how many
minutes, seconds and milliseconds will have been passed to beat that record after 1 day passed.
Write a C program that gets a Guinness World Record in hours:minutes:seconds.milliseconds format (until a negative value
for any one of those is entered) and finds minutes, seconds and milliseconds passed to beat that record.
Example Run:
Enter a guiness record in the given format (hours:minutes:seconds:milliseconds): 1:23:45.67