首页 > > 详细

UESTC 1005课程代写、Programming编程代做、c/c++程序语言调试代做留学生Prolog|调试Matlab程序

UESTC 1005 – Introductory Programming Page 1 of 2
Lab Session - Pointers
Exercise 1: Pointers
Background
Pointers: stuff from lecture notes.
To keep track of time, computers need something to measure it against. In C on the lab
computers, we get the number of seconds since 00:00:00 UTC on 1 January 1970.
As you might imagine, this produces a fairly large number -- it exceeds the bounds of a
normal int. We therefore use a long int, which has twice the number of bits of a
normal int. Our time.h library also defines a special data type to store the time value:
time_t. On our computers, this is the same as a long int.
Technical details
Swapping data with pointers:
#include
void swap(int *px, int *py) {
int temp = *px;
*px = *py;
*py = temp;
}
int main() {
int x = 1;
int y = 2;
printf("initial: %i %i\n", x, y);
swap( &x, &y);
printf("swapped: %i %i\n", x, y);
getchar();
return 0;
}
Watch out for the * and &
Getting the time:
#include
#include // extra include
int main() {
time_t now;
now = time(NULL);
long int a = now;
printf("%li\n", now); }
UESTC 1005 – Introductory Programming Page 2 of 2
getchar();
return 0;
}
Your task...
Calling time(NULL) gives you a large integer. Use this value to calculate today's year,
date, hours, and minutes.
• Simplifying assumption: we pretend that each year has exactly 365 days. The 15th of
March is therefore day 83 in year 2011. (use that date to figure out today's "day
number")
(hint: how many seconds are there in a day?)
• You cannot use struct for this assignment.
• You cannot use any time-based functions from the standard library such
asasctime or strftime.
• You must use one function to calculate the year and day (pass in the total seconds,
and a reference to the year and day).
• You must use a separate function to calculate the hours and minutes. (again, pass the
total seconds, and a reference to the hours and minutes)
• You must use a separate function to print the time; this function can only take as
arguments the year, day, hour, and minutes.
(optional: handle leap-years correctly, and print the month as well)
Note: Show your work to a demonstrator/GTA.

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp
热点文章
程序代写更多图片

联系我们 - QQ: 99515681 微信:codinghelp
© 2014 www.7daixie.com
程序代写网!