1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 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 72 73 74 75 76 77
|
1 //Sam Vernaza CS162 Lab # 4
2 // Practice with functions
3 #include <iostream>
4 #include <cctype>
5 #include <cstring>
6
7 using namespace std;
8
9 // prototypes here:
10
11 const int NAME = 21;
12 const int ARRAY= 22;
13 const int CRNNAME = 4;
14
15 void user_name (char first [], char last []); //username void function
16 void user_course (int& crn, char course [], int& section);// coures void function
17
18
19
20 int main()
21 {
22 char first[NAME]; // First name array
23 char last[ARRAY]; // First name array
24 int crn;
25 char course;
26 int section;
27
28 user_name(first,last); // user name function call
29 user_course(crn, course, section);// course function call
30
31 return 0;
32 }
33
34 void user_name (char first[], char last[]) //username function
35 {
36
37 char response;
38
39 cout << "Enter your name:" << endl;
40 cin.get(first, NAME,'\n');
41 cin.ignore(100,'\n');
42 // response = toupper(first[0]);
43
44
45 cout << "Enter Last Name;" << endl;
46 cin.get(last,ARRAY,'\n');
47 cin.ignore(100,'\n');
48 response = toupper(last[0]);
49
50 cout << "You've Entered: " << first << ' ' << last << endl;
51 }
52
53
54 void user_course(int& crn, char course[], int& section); // courses fucntion
55
56 {
57 cout << "Enter CRN # (3 numbers): " << endl;
58 cin >> crn;
59 cin.ignore (100, '\n');
60
61 cout << "Enter Course Designator(ex CS162): " << endl;
62 cin.get(course, 6, '\n');
63 cin.ignore(100, '\n');
64
65 cout << "Course Section: " << endl;
66 cin >> section;
67 cin.ignore(100, '\n');
68
69 cout << "Your courses are:\n"
70 << "CRN # "<< crn << '\n'
71 << "Course: " << course << '\n'
72 << "Section: " << section << endl;
73 }
74
75
76
|