COMP1511 Revision Characters Exercises PDF

Title COMP1511 Revision Characters Exercises
Course Introduction to Programming
Institution University of New South Wales
Pages 8
File Size 361.6 KB
File Type PDF
Total Downloads 14
Total Views 141

Summary

Exam Revision Notes...


Description

09/05/2019

COMP1511 Revision Characters Exercises

COMP1511 19T1

Characters

Exercises

Revision Exercise: Character Numbers Computers encode characters (letters, numbers, and symbols) as numbers. For this exercise we'll used. As a side note, ASCII is a subset of the most widely used modern character encoding: UTF-8 In ASCII the integers (0-31) represent control characters, which don't print anything. Similarly, th another special character, the delete character. The integers 32 to 126 are printing characters - for represents an asterisk ('*') character. Create a C program called character_numbers.c which prints the integers 32 to 126 in decimal character they represent in ASCII. Match the example output below EXACTLY:

09/05/2019

COMP1511 Revision Characters Exercises

$ dcc character_numbers.c -o character_numbers $ ./character_numbers

32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71

0x20 0x21 0x22 0x23 0x24 0x25 0x26 0x27 0x28 0x29 0x2a 0x2b 0x2c 0x2d 0x2e 0x2f 0x30 0x31 0x32 0x33 0x34 0x35 0x36 0x37 0x38 0x39 0x3a 0x3b 0x3c 0x3d 0x3e 0x3f 0x40 0x41 0x42 0x43 0x44 0x45 0x46 0x47

! " # $ % & ' ( ) * + , . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G

09/05/2019

COMP1511 Revision Characters Exercises

87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126

0x57 0x58 0x59 0x5a 0x5b 0x5c 0x5d 0x5e 0x5f 0x60 0x61 0x62 0x63 0x64 0x65 0x66 0x67 0x68 0x69 0x6a 0x6b 0x6c 0x6d 0x6e 0x6f 0x70 0x71 0x72 0x73 0x74 0x75 0x76 0x77 0x78 0x79 0x7a 0x7b 0x7c 0x7d 0x7e

W X Y Z [ \ ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~

When you think your program is working you can use autotest to run some simple automated te

09/05/2019

COMP1511 Revision Characters Exercises

key - Ctrl-D

This will cause getchar() to return the special EOF value.

putchar() takes a single character (byte) as a parameter and prints it to standard output. For example:

$ dcc parrot.c -o parrot $ ./parrot abc

abc ABCabc123

ABCabc123 abc

abc xyz

xyz Ctrl-D When you think your program is working you can use autotest to run some simple automated te

$ 1511 autotest parrot

Autotest Results 99% of 310 students who have autotested parrot.c so far, passed all autotest tests. 99% passed test parrot_0 99% passed test parrot_1 99% passed test parrot_2 99% passed test parrot_3 99% passed test parrot_4

Revision Exercise: Text To Int You should make sure you have completed parrot before completing this task.

Write a program text_to_int.c which reads characters and prints their decimal values, each on Copy your parrot.c file and use it as a starting point. For example:

09/05/2019

COMP1511 Revision Characters Exercises

$ ./text_to_int abc

97 98 99 10 17

49 55 10 Hello, world!

72 101 108 108 111 44 32 119 111 114 108 100 33 10 17 is my favourite number.

49 55 32 105 115 32 109 121 32 102 97 118 111 117 114 105

09/05/2019

COMP1511 Revision Characters Exercises

$ 1511 autotest text_to_int

Autotest Results 99% of 301 students who have autotested text_to_int.c so far, passed all autotest tests. 99% passed test tti_0 99% passed test tti_1 99% passed test tti_2 99% passed test tti_3 99% passed test tti_4

Revision Exercise: Lowercase Download lowercase.c here, or copy it to your CSE account using the following command:

$ cp -n /web/cs1511/19T1/activities/lowercase/lowercase.c . Your task is to add code to this function in lowercase.c: // Returns the specified character `c`, in lowercase. int lowercase(int c) { // Your code goes here! // Don't forget to return your result. return 0; } The function lowercase takes in a character, c and if it is an uppercase letter, converts it to lower other input values should be returned unchanged. Here is how lowercase.c should behave after you add the correct code to the function lowercase

$ dcc lowercase.c -o lowercase $ ./lowercase ABC

abc ABCabc123

abcabc123 123!@#

123!@# When you think your program is working you can use autotest to run some simple automated te

$ 1511 autotest lowercase

Autotest Results 99% of 280 students who have autotested lowercase.c so far, passed all autotest tests.

09/05/2019

COMP1511 Revision Characters Exercises

int uppercase(int c) { // PUT YOUR CODE HERE return 0; // change to your return value } The function uppercase takes in a character, c and if it is an uppercase letter, converts it to upper other input values should be returned unchanged. Here is how uppercase.c should behave after you add the correct code to the function uppercase

$ dcc uppercase.c -o uppercase $ ./uppercase abc

ABC ABCabc123

ABCABC123 123!@#

123!@# When you think your program is working you can use autotest to run some simple automated te

$ 1511 autotest uppercase

Autotest Results 100% of 252 students who have autotested uppercase.c so far, passed all autotest tests.

Revision Exercise: Rotate One Download rotate_one.c here, or copy it to your CSE account using the following command:

$ cp -n /web/cs1511/19T1/activities/rotate_one/rotate_one.c . Your task is to add code to this function in rotate_one.c: // "Rotate" the letter by one, i.e. change 'a' to 'b', 'b' to 'c', // 'z' to 'a'. int rotateOne(int c) { // Your code goes here! // Don't forget to return your result. return 0; } The rotate_one function should "rotate" a letter through the alphabet by one position. This means that if the input is 'a', the output should be 'b'. 'z' becomes 'a' and 'Z' becomes 'A'.

09/05/2019

COMP1511 Revision Characters Exercises 99% passed test r1_0 99% passed test r1_1 98% passed test r1_2 97% passed test r1_3

COMP1511 19T1: Programming Fundamentals is brought to you the School of Computer Science and Engineering at the University of New Sout For all enquiries, please email the class account at [email protected]. CRICOS Provider 00098G...


Similar Free PDFs