# UESTC 1005课程代写、Programming编程代做

UESTC 1005课程代写、Programming编程代做

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 <stdio.h>

void swap(int *px, int *py) {

int temp = *px;

*px = *py;

*py = temp;

}

int main() {

int x = 1;

int y = 2;

printf("initial: %i %in", x, y);

swap( &x, &y);

printf("swapped: %i %in", x, y);

getchar();

return 0;

}

Watch out for the * and &

Getting the time:

#include <stdio.h>

#include <time.h> // extra include

int main() {

time_t now;

now = time(NULL);

long int a = now;

printf("%lin", now); }

UESTC 1005 – Introductory Programming Page 2 of 2

getchar();

return 0;

}

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.

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 <stdio.h>

void swap(int *px, int *py) {

int temp = *px;

*px = *py;

*py = temp;

}

int main() {

int x = 1;

int y = 2;

printf("initial: %i %in", x, y);

swap( &x, &y);

printf("swapped: %i %in", x, y);

getchar();

return 0;

}

Watch out for the * and &

Getting the time:

#include <stdio.h>

#include <time.h> // extra include

int main() {

time_t now;

now = time(NULL);

long int a = now;

printf("%lin", now); }

UESTC 1005 – Introductory Programming Page 2 of 2

getchar();

return 0;

}

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.

### 站点精选

2015年，安徽省安庆市在拿下省级文明城市称号后，首次获全国文明城市提名并启动全国文明城市创建工作，自此，该市踏上了三年一个周期的“创城”征程。2016年，安徽...