首页 > > 详细

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: 9951568
© 2021 www.rj363.com
软件定制开发网!