Skip to content

Instantly share code, notes, and snippets.

@itguy51
Created April 29, 2015 04:24
Show Gist options
  • Save itguy51/7212f24b68667ed937c8 to your computer and use it in GitHub Desktop.
Save itguy51/7212f24b68667ed937c8 to your computer and use it in GitHub Desktop.
ECE 114 09
#include "include.h"
int main(){
while (true)
{
std::cout << "1. Plane Passengers\n2. SNR calculator\n3. Taylor Series\n4. Exit\n\nEnter Choice: ";
int choice;
std::cin >> choice;
if (choice == 1)
{
int flight1_3 = 0;
int flight1_4 = 0;
int flight1_5 = 0;
int flight2_3 = 0;
int flight2_4 = 0;
int flight2_5 = 0;
while (true){
int numToAdd;
std::cout << "Number of passengers to add [0 to end.]: ";
std::cin >> numToAdd;
if (numToAdd > 0)
{
while (numToAdd > 0)
{
std::cout << "Flight Class: ";
int fn;
std::cin >> fn;
if (fn == 1)
{
std::cout << "No 1st class seating available.\n";
continue;
}
else if (fn == 2)
{
std::cout << "No 2nd class seating available.\n";
continue;
} else if (fn >= 3 && fn <= 5)
{
int flightNum;
std::cout << "Enter Flight Number: ";
std::cin >> flightNum;
if (flightNum == 1)
{
switch (fn)
{
case 3:
flight1_3++;
break;
case 4:
flight1_4++;
break;
case 5:
flight1_5++;
break;
}
} else if (flightNum == 2)
{
switch (fn)
{
case 3:
flight2_3++;
break;
case 4:
flight2_4++;
break;
case 5:
flight2_5++;
break;
}
}
} else
{
std::cout << "No " << fn <<"th class seating available.\n";
continue;
}
numToAdd--;
}
} else
{
break;
}
}
printf("Flight 1: %i Class 3, %i Class 4, %i Class 5\nFlight 2: %i Class 3, %i Class 4, %i Class 5\n\n", flight1_3, flight1_4, flight1_5, flight2_3, flight2_4, flight2_5);
} else if (choice == 2)
{
std::cout << "Enter Epsilon Value: " ;
double evalue;
std::cin >> evalue;
printf("SNR_v = %3.10f\n\n", calcSNR_v(evalue));
} else if (choice == 3)
{
std::cout << "Enter X value: ";
int x;
std::cin >> x;
double remVal = 1e-12;
double total = 0.0;
int count = 0;
while (true)
{
double elem = pow(x, (double)count) / factorial(count);
total += elem;
if (elem < remVal)
{
break;
}
count++;
}
printf("e^%i = %4.10f\n\n", x, total);
} else if (choice == 4)
{
break;
}
else
{
std::cout << "Not an option\n\n";
}
}
return 0;
}
#include "include.h"
double calcSNR_v(double epsilon)
{
double res;
if (epsilon <= 1.6755)
{
res = sqrt(M_PI / (4 - M_PI))*((pow(epsilon, 2.0) / 4.0) - (pow(epsilon, 4.0) / 64.0) + (pow(epsilon, 6.0) / 768.0));
} else
{
res = sqrt(2.0 / (4 - M_PI))*(
epsilon - sqrt(M_PI / 2)
+ (1 / (2 * epsilon))
+ (1 / (8 * pow(epsilon, 3.0)))
+ (3 / (16 * pow(epsilon, 5.0)))
);
}
return res;
}
int factorial(int n)
{
return (n == 1 || n == 0) ? 1 : factorial(n - 1) * n;
}
#include <iostream>
# define M_PI 3.14159265358979323846 /* pi */
double calcSNR_v(double epsilon);
int factorial(int n);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment