This commit is contained in:
clarissa 2023-09-27 17:18:26 -07:00
parent 409122ab68
commit b57b7058be
10 changed files with 84 additions and 0 deletions

View File

@ -1,2 +1,3 @@
# cs161examples
These are code snippets and examples for cs161A/B

34
cs161BW1/average.cpp Normal file
View File

@ -0,0 +1,34 @@
#include <iostream>
using namespace std;
// program for calculating the average of an arbitrary number of inputs
double totalSum(int &counter){
double sum = 0;
double temp = 0;
do {
cout << "Please enter a number or type quit: ";
cin >> temp;
if(cin){
counter = counter + 1;
sum = sum + temp;
}
}
while(cin);
return sum;
}
int main(){
int count = 0;
double total = 0;
total = totalSum(count);
if(count > 0){
cout << "The total sum is: " << total << endl;
cout << "The average is: " << total / (double)count << endl;
}
}

BIN
cs161BW1/sarcasmCase Executable file

Binary file not shown.

32
cs161BW1/sarcasmCase.cpp Normal file
View File

@ -0,0 +1,32 @@
#include <iostream>
#include <cctype>
using namespace std;
void makeSarcastic(char str[]){
int i = 0;
bool upper = false;
while(str[i] != '\0'){
if(upper){
str[i] = toupper(str[i]);
}
else{
str[i] = tolower(str[i]);
}
upper = !upper;
i = i + 1;
}
}
int main(){
char msg[100];
cout << "Enter text to be made more sarcastic: " << endl;
cin.getline(msg,100);
makeSarcastic(msg);
cout << msg << endl;
return 0;
}

17
cs161BW1/sarcasmCase.cpp~ Normal file
View File

@ -0,0 +1,17 @@
#include <iostream>
#include <cctype>
void makeSarcastic
int main(){
char msg[100];
cout << "Enter text to be made more sarcastic: " << endl;
cin >> msg;
makeSarcastic(msg);
cout << msg << endl;
return 0;
}