## CSCE 1040 Lab 9

0 likes • Nov 18, 2022 • 2 views
C++

## More C++ Posts

#### C++ SigFigs

0 likes • Sep 7, 2022 • 0 views
C++
`#include <iostream>#include <cstring>int main(int argc, char** argv){	//With decimal	if(strstr(argv[1], ".") != nullptr){		int i = 0;		//Skip i to first non 0 digit		while(argv[1][i] < '1' || argv[1][i] > '9') ++i;		//If digit comes before decimal		if((argv[1] + i) < strstr(argv[1], ".")){	//Good example of pointer arithmetic			std::cout << strlen(argv[1] + i) - 1 << std::endl;	//Another good example		}else{			//If digit is after decimal			std::cout << strlen(argv[1] + i) << std::endl;		}	}else{	//Without decimal		int m = 0;		int i = 0;		while(argv[1][i] < '1' || argv[1][i] > '9') ++i;	//In case of some number like 0045		for(; argv[1][i] != '\0'; ++i){			if(argv[1][i] >= '1' && argv[1][i] <= '9') m = i + 1;		}		std::cout << m << std::endl;	}	return 0;}`

#### Hello, World!

0 likes • Nov 18, 2022 • 2 views
C++
```#include <iostream>using namespace std;
int main(){    cout << "Hello, World!" << endl;    return 0;}```

#### Parking Lot Simulation

0 likes • Nov 18, 2022 • 1 view
C++
```#include<iostream>#include<fstream>#include<vector>#include<stdio.h> #include<time.h>#include<stdlib.h>using namespace std;
//data storage for parking lot info, admin, managers, users, and ticketsstruct Parking_Lot_info{	int total_Space;	int regular;	int motorcycle;	int disability;};struct Admin{	string name;	string id;	string password;};struct Manager{	string name;	string id;	string password;}; struct User{	string id;	string name;	string password;	string makeModel1;	string makeModel2;	string year;	string plate;};struct Ticket{	string ticket_Number;	string ticket_Amount;	string ticket_Issued;	string ticket_Status;	string reason; 	string plate;};

void Initial_Manager_Vector(char management_People_File_Name[]){	ifstream in;	Manager m;	in.open(management_People_File_Name);	while(getline(in,m.name,',')){		getline(in,m.id,',');		getline(in,m.password);		manager_Vector.push_back(m);	}	in.close();}void Initial_User_Vector(char user_People_File_Name[]){	ifstream in;	User u;	in.open(user_People_File_Name);	while(getline(in,u.name,',')){		getline(in,u.id,',');		getline(in,u.password,',');		getline(in,u.makeModel1,',');		getline(in,u.makeModel2,',');		getline(in,u.year,',');		getline(in,u.plate);		user_Vector.push_back(u);	}	in.close();}void Initial_Ticket_Vector(){	ifstream in;	Ticket t;	in.open("ticket.csv");	while(getline(in,t.ticket_Number,',')){		getline(in,t.ticket_Amount,',');		getline(in,t.ticket_Issued,',');		getline(in,t.ticket_Status,',');		getline(in,t.reason,',');		getline(in,t.plate);		ticket_Vector.push_back(t);	}	in.close();}

int main(){        //char array to store the user input for the file search	char input_File_Name[100]; 	char admin_People_File_Name[100];	char management_People_File_Name[100];	char user_People_File_Name[100];		ifstream in; 	Parking_Lot_info *pli; //Structure pointer	int pln; //Parking lot number	int max_Space = 8; // Max number of parking space in a row	int t = 0; //Determine when it needs to switch to the next row		//relevant strings for admin, management, and users	string admin_Name, admin_Id, admin_Password;	string management_Name, management_Id, management_Password;	string user_Name, user_Id, user_Password;		string user_Make_Model1, user_Make_Model2, user_Year, user_Plate_Number;
//get filename	cout << "Enter file name: "; 	cin.getline(input_File_Name,100);	in.open(input_File_Name);	if(!in){		cout << "Can't open the file!" << endl; //error check		return 0;	}

#### Stock Options Analyzer

0 likes • Nov 18, 2022 • 0 views
C++
```#include <iostream>#include <cmath>#include <string.h>
using namespace std;
int main() {
string tickerName;    int numOfContracts;    float currentOptionValue;
cout << "Enter a stock ticker: ";    getline(cin, tickerName);
cout << "Enter the current number of " << tickerName << " contracts you are holding: ";    cin >> numOfContracts;

cout << "Enter the current price of the option: ";    cin >> currentOptionValue;

cout << "The value of your " << tickerName << " options are: \$" << (currentOptionValue * 100.00) * (numOfContracts);
cout << endl;
return 0;}```

#### Heapify a vector

0 likes • Nov 19, 2022 • 0 views
C++
```#include <iostream>#include <vector>using namespace std;
void swap(int *a, int *b){  int temp = *b;  *b = *a;  *a = temp;}void heapify(vector<int> &hT, int i){  int size = hT.size();  int largest = i;  int l = 2 * i + 1;  int r = 2 * i + 2;  if (l < size && hT[l] > hT[largest])    largest = l;  if (r < size && hT[r] > hT[largest])    largest = r;
if (largest != i)  {    swap(&hT[i], &hT[largest]);    heapify(hT, largest);  }}void insert(vector<int> &hT, int newNum){  int size = hT.size();  if (size == 0)  {    hT.push_back(newNum);  }  else  {    hT.push_back(newNum);    for (int i = size / 2 - 1; i >= 0; i--)    {      heapify(hT, i);    }  }}void deleteNode(vector<int> &hT, int num){  int size = hT.size();  int i;  for (i = 0; i < size; i++)  {    if (num == hT[i])      break;  }  swap(&hT[i], &hT[size - 1]);
hT.pop_back();  for (int i = size / 2 - 1; i >= 0; i--)  {    heapify(hT, i);  }}void printArray(vector<int> &hT){  for (int i = 0; i < hT.size(); ++i)    cout << hT[i] << " ";  cout << "\n";}
int main(){  vector<int> heapTree;
insert(heapTree, 3);  insert(heapTree, 4);  insert(heapTree, 9);  insert(heapTree, 5);  insert(heapTree, 2);
cout << "Max-Heap array: ";  printArray(heapTree);
deleteNode(heapTree, 4);
cout << "After deleting an element: ";
printArray(heapTree);}```

#### Critques

0 likes • Feb 4, 2021 • 0 views
C++
```#include <iostream>using namespace std;
main{	cout << "No tabbing. That's very sad :(\n";	cout << "No in-editor highlighting either :(((\n";	cout << "Descriptions might be niice too.";}```