-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththeWeek1Code.cpp
More file actions
88 lines (70 loc) · 2.21 KB
/
theWeek1Code.cpp
File metadata and controls
88 lines (70 loc) · 2.21 KB
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
78
79
80
81
82
83
84
85
86
87
88
// Sample IP1 Program
// Created by Dr. Evans for CS215 - Intermediate C++
// Individual project 1
// Winter 2016
//#include "stdafx.h"
// #include "GreetingMessage.h"
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main(int argc, char *argv[])
{
// Variables
int r = 3; //# of records to be generated
string studentName[3];
double GPA[3];
string lName;
string fName;
// Set floating point values to two decimal places
cout << setiosflags(ios::fixed);
cout << setiosflags(ios::showpoint);
cout << setprecision(2);
// gather student names & GPAs
for (int i = 0; i < r; i++)
{
if (i== 0){
cout << "Student " << + i+1 <<endl;
cout << "Enter Name (Last, First): ";
getline (cin, studentName[i]);
cout << "GPA: ";
cin >> GPA[i];
} else
{
cout << "Enter Name (Last, First): ";
cin.ignore();
getline (cin, studentName[i]);
cout << "GPA: ";
cin >> GPA[i];
}
}
//print column names
cout << setfill(' ') << setw(25) << left << "Student Name" << setw(5) << right << "GPA" << endl;
// set letter case in studentNames array
for (int i = 0; i < r; i++)
{
// separate first and last names
string::size_type commaPos = studentName[i].find(","); //find ","
lName = studentName[i].substr(0, commaPos); // select last name
fName = studentName[i].substr(commaPos + 1); // select first name
if (fName[0] == ' ') fName.erase(0, 1); // remove blank space between "," and first letter of first name
// set all letters in first name to lower case, and then set first letter to upper case
for (int x = 0; x < fName.length(); x++)
{
fName[x] = tolower(fName[x]);
}
fName[0] = toupper(fName[0]);
// set all letters in last name to lower case, and then set first letter to upper case
for (int x = 0; x < lName.length(); x++)
{
lName[x] = tolower(lName[x]);
}
lName[0] = toupper(lName[0]);
// set original studentName variable to proper case formatting
studentName[i] = lName + ", " + fName;
// print student record
cout << setfill(' ') << setw(25) << left << studentName[i] << setw(5) << right << GPA[i] << endl;
}
//system("pause");
return 0;
}