Getting Bluetooth LMP version via Powershell - powershell

I have taken a look at CIM_NetworkAdapter, Get-NetAdapterAdvancedProperty CIM_LogicalDevice, Win32_PnPDevice and more.
How can I go about grabbing the LMP version of a Bluetooth adapter from its "Bluetooth Radio Information" in its advanced properties?
Is this possible in Regedit -or any other way?
EDIT,
ANSWER:
Here's a modified version of an answer I received on Reddit from u/ChaosTheoryRules
$BTDevices = Get-PnpDevice -Class "Bluetooth"
Foreach ($device in $BTDevices) {
$BTDeviceProperty = Get-PnpDeviceProperty -KeyName "DEVPKEY_Bluetooth_RadioLmpVersion" -InstanceId $device.InstanceID
If ($BTDeviceProperty -And $BtDeviceProperty.Data) {
$bluetoothVersion = Switch ($BTDeviceProperty.Data) {
0 { '1.0b' }
1 { '1.1' }
2 { '1.2' }
3 { '2.0 + EDR' }
4 { '2.1 + EDR' }
5 { '3.0 + HS' }
6 { '4.0' }
7 { '4.1' }
8 { '4.2' }
9 { '5.0'}
10 { '5.1' }
11 { '5.2' }
default { "UKNOWN" }
}
}
}
Write-Host $bluetoothVersion
https://www.reddit.com/r/PowerShell/comments/vmexhm/getting_bluetooth_lmp_version_via_powershell/

I don't have the equipment to test, so I can only provide some reference documentation.
You can use BluetoothGetRadioInfo and the structure BLUETOOTH_RADIO_INFO to get relevant information lmpSubversion.
#include <windows.h>
#include <BluetoothAPIs.h>
#include <conio.h>
#include <iostream>
#include <string>
#include <locale>
#pragma comment(lib,"Bthprops.lib")
using namespace std;
int main(void)
{
wcout.imbue(locale(""));
HBLUETOOTH_RADIO_FIND hbf = NULL;
HANDLE hbr = NULL;
HBLUETOOTH_DEVICE_FIND hbdf = NULL;
BLUETOOTH_FIND_RADIO_PARAMS btfrp = { sizeof(BLUETOOTH_FIND_RADIO_PARAMS) };
BLUETOOTH_RADIO_INFO bri = { sizeof(BLUETOOTH_RADIO_INFO)};
BLUETOOTH_DEVICE_SEARCH_PARAMS btsp = { sizeof(BLUETOOTH_DEVICE_SEARCH_PARAMS) };
BLUETOOTH_DEVICE_INFO btdi = { sizeof(BLUETOOTH_DEVICE_INFO) };
hbf=BluetoothFindFirstRadio(&btfrp, &hbr);
bool brfind = hbf != NULL;
while (brfind)
{
if (BluetoothGetRadioInfo(hbr, &bri) == ERROR_SUCCESS)
{
cout << "Class of device: 0x" << uppercase << hex << bri.ulClassofDevice << endl;
wcout <<"Name:"<< bri.szName << endl;
cout <<"Manufacture:0x"<< uppercase << hex << bri.manufacturer << endl;
cout << "Subversion:0x" << uppercase << hex << bri.lmpSubversion << endl;
//
btsp.hRadio = hbr;
btsp.fReturnAuthenticated = TRUE;
btsp.fReturnConnected = FALSE;
btsp.fReturnRemembered = TRUE;
btsp.fReturnUnknown = TRUE;
btsp.cTimeoutMultiplier = 30;
hbdf=BluetoothFindFirstDevice(&btsp, &btdi);
bool bfind = hbdf != NULL;
while (bfind)
{
wcout << "[Name]:" << btdi.szName;
cout << ",[Address]:0x" << uppercase << hex << btdi.Address.ullLong << endl;
bfind=BluetoothFindNextDevice(hbdf, &btdi);
}
BluetoothFindDeviceClose(hbdf);
}
CloseHandle(hbr);
brfind=BluetoothFindNextRadio(hbf, &hbr);
}
BluetoothFindRadioClose(hbf);
_getch();
return 0;
}

Related

how can I disable windows micphone enhancement by c++ code?

is there a way to disable the microphone audio enhancements from C++ code?
We are doing some audio processing things on the incoming microphone signal, and the microphone enhancements cause all kinds of trouble. We know we can turn it off manually on Windows10 by going to the Control panel --> Sound --> Recording --> Microphone --> Properties --> advanced--> Enhancements, but we need a way to do this from code.
enter image description here
when I try to access it via C++ It comes back saying there is no AGC on the device.
void AudioDeviceWindowsCore::DisableHardwareAGC() {
// get device topology object for that endpoint
CComPtr<IDeviceTopology> pTopo = NULL;
HRESULT ret = _ptrDeviceIn->Activate(__uuidof(IDeviceTopology), CLSCTX_ALL, NULL,
(void**)&pTopo);
if (FAILED(ret)) {
RTC_LOG(LS_ERROR) << "Couldn't get device topology object: hr = 0x"
<< rtc::ToHex(ret);
} else {
UINT count = 0;
pTopo->GetConnectorCount(&count);
CComPtr<IConnector> pConn = NULL;
ret = pTopo->GetConnector(0, &pConn);
if (FAILED(ret)) {
RTC_LOG(LS_ERROR) << __FUNCTION__ << " GetConnector:" << rtc::ToHex(ret);
return ;
}
CComPtr<IConnector> pConnNext = NULL;
ret = pConn->GetConnectedTo(&pConnNext);
if (FAILED(ret)) {
RTC_LOG(LS_ERROR) << __FUNCTION__
<< " GetConnectedTo:" << rtc::ToHex(ret);
return ;
}
CComPtr<IPart> pPart = NULL;
const IID IID_IPart = __uuidof(IPart);
ret = pConnNext->QueryInterface(IID_IPart, (void**)&pPart);
if (FAILED(ret)) {
RTC_LOG(LS_ERROR) << __FUNCTION__
<< " QueryInterface:" << rtc::ToHex(ret);
return ;
}
// all the real work is done in this function
ret = WalkTreeForwardsFromPart(pPart);
if (SUCCEEDED(ret)) {
RTC_LOG(INFO) << " now close hardware AGC ret:" << rtc::ToHex(ret);
} else {
RTC_LOG(INFO) << " Hardware not Supports Microphone AGC";
}
}
}
HRESULT WalkTreeForwardsFromPart(IPart* pPart) {
HRESULT hr = S_OK;
LPWSTR pwszPartName = NULL;
hr = pPart->GetName(&pwszPartName);
if (FAILED(hr)) {
RTC_LOG(LS_ERROR) << "Could not get part name: hr = 0x"<<rtc::ToHex(hr);
return hr;
}
RTC_LOG(INFO) << "Part name: " << *pwszPartName ? pwszPartName : L"Unnamed";
CoTaskMemFree(pwszPartName);
GUID type_id;
hr = pPart->GetSubType(&type_id);
if (hr == S_OK){
if (IsEqualGUID(type_id,KSNODETYPE_LOUDNESS) ) {
const IID IID_IAudioLoudness = __uuidof(IAudioLoudness);
IAudioLoudness* loudness = NULL;
hr = pPart->Activate(CLSCTX_ALL, IID_IAudioLoudness, (void**)&loudness);
if (E_NOINTERFACE == hr) {
RTC_LOG(LS_ERROR) << "NO AudioLoudness CONTROL";
// not a Microphone node
} else if (FAILED(hr)) {
RTC_LOG(LS_ERROR) << "Unexpected failure trying to activate "
"IID_IAudioLoudness : hr = 0x"
<< rtc::ToHex(hr);
} else {
// it's an AGC node...
RTC_LOG(INFO) << "HAS IAudioLoudness CONTROL";
hr = loudness->SetEnabled(0, NULL);
if (FAILED(hr)) {
RTC_LOG(LS_ERROR)
<< "AudioLoudness Failed: hr = 0x" << rtc::ToHex(hr);
loudness->Release();
return hr;
}
loudness->Release();
}
} else if (IsEqualGUID(type_id, KSNODETYPE_AGC)) {
// Check AGC settings
const IID IID_IAudioAutoGainControl = __uuidof(IAudioAutoGainControl);
IAudioAutoGainControl* aGCcontrol = NULL;
hr = pPart->Activate(CLSCTX_ALL, IID_IAudioAutoGainControl,
(void**)&aGCcontrol);
if (E_NOINTERFACE == hr) {
RTC_LOG(LS_ERROR) << "NO AGC CONTROL";
// not a Microphone node
} else if (FAILED(hr)) {
RTC_LOG(LS_ERROR) << "Unexpected failure trying to activate "
"IAudioAutoGainControl : hr = 0x"
<< rtc::ToHex(hr);
return hr;
} else {
// it's an AGC node...
RTC_LOG(INFO) << "HAS AGC CONTROL";
aGCcontrol->SetEnabled(0, NULL);
if (FAILED(hr)) {
RTC_LOG(LS_ERROR) << "AGC Failed: hr = 0x" << rtc::ToHex(hr);
aGCcontrol->Release();
return hr;
}
aGCcontrol->Release();
}
}
}
// get the list of incoming parts
IPartsList* pOutgoingParts = NULL;
hr = pPart->EnumPartsOutgoing(&pOutgoingParts);
if (E_NOTFOUND == hr) {
// not an error... we've just reached the end of the path
RTC_LOG(INFO) << "No incoming parts at this part";
return hr;
}
if (FAILED(hr)) {
RTC_LOG(LS_ERROR) << " Couldn't enum outgoing parts";
return hr;
}
UINT nParts = 0;
hr = pOutgoingParts->GetCount(&nParts);
if (FAILED(hr)) {
RTC_LOG(LS_ERROR) << "Couldn't get count of outgoing parts";
pOutgoingParts->Release();
return hr;
}
// walk the tree on each incoming part recursively
for (UINT n = 0; n < nParts; n++) {
IPart* pOutgoingPart = NULL;
hr = pOutgoingParts->GetPart(n, &pOutgoingPart);
if (FAILED(hr)) {
RTC_LOG(LS_ERROR) << "Couldn't get part ";
pOutgoingParts->Release();
return hr;
}
hr = WalkTreeForwardsFromPart(pOutgoingPart);
if (FAILED(hr)) {
RTC_LOG(LS_ERROR) << " Couldn't walk tree on part";
pOutgoingPart->Release();
pOutgoingParts->Release();
return hr;
}
pOutgoingPart->Release();
}
pOutgoingParts->Release();
return S_OK;
}

Function Pointers in C++ Class Files

I've been trying to work with function pointers for quite a bit now, and to no avail. I've been working with a few friends to create a C++ 11 library to make creating ASCII games easier, and I've personally been working on creating a menu class. The beef of the class is complete, but one issue - I can't get the buttons to call functions. I always get the error:
terminate called after throwing an instance of 'std::bad_function_call'
what(): bad_function_call
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
Obviously the error lies somewhere in the pointers, but I can't solve it for the life of me. Thanks for the help in advance.
Menu.h
#ifndef MENU_H
#define MENU_H
using namespace std;
#include <functional>
#include <string>
#include <map>
class Menu {
public:
int numberOfOptions;
map<int, string> options;
int currentSelection;
string title;
Menu();
Menu(int initialNumberOfOptions, map<int, string> initialOptions, int initialSelection);
void display();
void waitForInput();
void attachOptionAction(int option, void (*function)());
private:
map<int, void (*std::function<void()>)> optionActions;
void executeOptionAction(int option);
};
#endif
Menu.cpp
#include "Menu.h"
#include <windows.h>
#include <iostream>
#include <conio.h>
Menu::Menu(int initialNumberOfOptions, map<int, string> initialOptions, int initialSelection) {
title = "";
numberOfOptions = initialNumberOfOptions;
options = initialOptions;
currentSelection = initialSelection;
}
void Menu::display() {
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), {0, 0});
for(int i = 0; i < 10; i++) {
cout << " " << endl;
}
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), {0, 0});
if(title != "") {
cout << title << endl << endl;
}
for(int i = 0; i < numberOfOptions; i++) {
if(i == currentSelection - 1) {
cout << "[ " << options[i] << " ]" << endl;
} else {
cout << options[i] << endl;
}
}
waitForInput();
}
void Menu::waitForInput() {
char input;
while(!kbhit());
input = getch();
if(input == 72 && currentSelection > 1) {
currentSelection--;
} else if (input == 80 && currentSelection < numberOfOptions) {
currentSelection++;
} else if (input == 13) {
if(currentSelection == 1) {
executeOptionAction(1);
}
return;
}
display();
}
void Menu::attachOptionAction(int option, std::function<void()> function) {
optionActions[option] = function;
}
void Menu::executeOptionAction(int option) {
(optionActions[option])();
}
test.cpp
#include "Menu.h"
#include <unistd.h>
#include <iostream>
#include <iomanip>
#include <map>
void test() {
cout << "Hello, World!";
}
int main() {
map<int, string> options;
options[0] = "Play";
options[1] = "Help";
options[2] = "Quit";
Menu menu(3, options, 1);
menu.title = "ASCII Game Library 2015";
menu.display();
void (*actionPointer)() = NULL;
menu.attachOptionAction(1, (*actionPointer));
return 0;
}
This is wrong. I'm not even sure what's that supposed to be.
map<int, void (*std::function<void()>)> optionActions;
It should be:
map<int, std::function<void()>> optionActions;
This here is also wrong. It would be correct if you hadn't imported std into your current namespace.
void attachOptionAction(int option, void (*function)());
It should be:
void attachOptionAction(int option, const std::function<void()> & action);
This here is also wrong. You can't name your argument function after you imported std into your namespace.
void Menu::attachOptionAction(int option, std::function<void()> function)
It should be:
void Menu::attachOptionAction(int option, const std::function<void()> & action)
This here is also wrong. You don't check if the function exists or that a valid function pointer was assigned to it. Which you haven't.
(optionActions[option])();
It should be:
// Attempt to find the action!
map<int, std::function<void()>>::iterator action = optionActions.find(option);
// Did we find anything?
if (action == optionActions.end())
{
return;
}
// Is the function assigned to this action valid?
if (action->second)
{
action->second();
}
You are attaching a null function pointer to an action and try to call it. And since there's no validation it does exactly that. Which is why you get that exception:
void (*actionPointer)() = NULL;
menu.attachOptionAction(1, (*actionPointer));
But I'm not even sure how even managed to compile it :/
EDIT:
I hope you can find this example to be informative on what you're looking for.
#include <map>
#include <string>
#include <cstdlib>
#include <iostream>
#include <functional>
class Menu
{
protected:
typedef std::function<int (Menu &)> Callback;
typedef std::map<int, Menu> SubMenus;
public:
Menu()
: m_Id(0), m_Name(""), m_Handler(nullptr)
{
}
Menu(int id, const std::string & name, Callback clbk)
: m_Id(id), m_Name(name), m_Handler(clbk)
{
}
Menu & operator [] (int id)
{
return m_Childrens.at(id);
}
int Enter()
{
int result = 0;
if (m_Handler)
result = m_Handler(*this);
return result;
}
void Insert(const Menu & menu)
{
m_Childrens[menu.m_Id] = menu;
}
void Insert(int id, const std::string & name, Callback clbk)
{
m_Childrens[id] = Menu(id, name, clbk);
}
void Remove(int id)
{
m_Childrens.erase(id);
}
int GetId() const
{
return m_Id;
}
const std::string & GetName() const
{
return m_Name;
}
const Callback & GetHandler() const
{
return m_Handler;
}
bool IsChildren(int id) const
{
return (m_Childrens.find(id) != m_Childrens.cend());
}
Menu & GetChildren(int id)
{
return m_Childrens.at(id);
}
const SubMenus & GetChildrens() const
{
return m_Childrens;
}
private:
int m_Id;
std::string m_Name;
Callback m_Handler;
SubMenus m_Childrens;
};
void ClearScreen()
{
system("cls");
}
int SharedMenuDisplay(const Menu & menu)
{
ClearScreen();
std::cout << "Welcome to " << menu.GetName() << std::endl;
for (const auto & m : menu.GetChildrens())
{
std::cout << "> " << m.second.GetId() << " - " << m.second.GetName() << std::endl;
}
std::cout << "> 0 - Go Back" << std::endl;
std::cout << "Please select a sub menu: ";
int choice;
std::cin >> choice;
return choice;
}
int Menu_Home(Menu & menu)
{
int choice;
int result = 0;
do {
ClearScreen();
std::cout << "Welcome to " << menu.GetName() << std::endl;
for (const auto & m : menu.GetChildrens())
{
std::cout << "> " << m.second.GetId() << " - " << m.second.GetName() << std::endl;
}
std::cout << "> 0 - To Leave" << std::endl;
std::cout << "Please select a sub menu: ";
std::cin >> choice;
if (choice != 0 && menu.IsChildren(choice))
result = menu.GetChildren(choice).Enter();
} while (choice != 0);
return result;
}
int Menu_A(Menu & menu)
{
int choice;
int result = 0;
do {
choice = SharedMenuDisplay(menu);
if (choice != 0 && menu.IsChildren(choice))
result = menu.GetChildren(choice).Enter();
} while (choice != 0);
return result;
}
int Menu_A_SubMenu_X(Menu & menu)
{
ClearScreen();
std::cout << "You have selected " << menu.GetName() << std::endl;
std::cout << "> Type something and press Enter to go back..." << std::endl;
std::string str;
std::cin >> str;
return 0;
}
int Menu_A_SubMenu_Y(Menu & menu)
{
ClearScreen();
std::cout << "You have selected " << menu.GetName() << std::endl;
std::cout << "> Type something and press Enter to go back..." << std::endl;
std::string str;
std::cin >> str;
return 0;
}
int Menu_A_SubMenu_Z(Menu & menu)
{
ClearScreen();
std::cout << "You have selected " << menu.GetName() << std::endl;
std::cout << "> Type something and press Enter to go back..." << std::endl;
std::string str;
std::cin >> str;
return 0;
}
int Menu_B(Menu & menu)
{
int choice;
int result = 0;
do {
choice = SharedMenuDisplay(menu);
if (choice != 0 && menu.IsChildren(choice))
result = menu.GetChildren(choice).Enter();
} while (choice != 0);
return result;
}
int Menu_B_SubMenu_X(Menu & menu)
{
ClearScreen();
std::cout << "You have selected " << menu.GetName() << std::endl;
std::cout << "> Type something and press Enter to go back..." << std::endl;
std::string str;
std::cin >> str;
return 0;
}
int Menu_B_SubMenu_Y(Menu & menu)
{
ClearScreen();
std::cout << "You have selected " << menu.GetName() << std::endl;
std::cout << "> Type something and press Enter to go back..." << std::endl;
std::string str;
std::cin >> str;
return 0;
}
int Menu_B_SubMenu_Z(Menu & menu)
{
ClearScreen();
std::cout << "You have selected " << menu.GetName() << std::endl;
std::cout << "> Type something and press Enter to go back..." << std::endl;
std::string str;
std::cin >> str;
return 0;
}
int Menu_C(Menu & menu)
{
ClearScreen();
std::cout << "You have selected " << menu.GetName() << std::endl;
std::cout << "> Type something and press Enter to go back..." << std::endl;
std::string str;
std::cin >> str;
return 0;
}
int main(int argc, char **argv)
{
Menu home(-1, "Home", &Menu_Home);
home.Insert(1, "Menu Item A", &Menu_A);
home.Insert(2, "Menu Item B", &Menu_B);
home.Insert(3, "Menu Item C", &Menu_C);
home.GetChildren(1).Insert(1, "Sub Menu Item X", &Menu_A_SubMenu_X);
home.GetChildren(1).Insert(2, "Sub Menu Item Y", &Menu_A_SubMenu_Y);
home.GetChildren(1).Insert(3, "Sub Menu Item Z", &Menu_A_SubMenu_Z);
home[2].Insert(1, "Sub Menu Item X", &Menu_B_SubMenu_X);
home[2].Insert(2, "Sub Menu Item Y", &Menu_B_SubMenu_Y);
home[2].Insert(3, "Sub Menu Item Z", &Menu_B_SubMenu_Z);
return home.Enter();
}

Random number generator sometimes fails to start in Eclipse

I have written some code that produces an object which returns a unique random number when queried. However, every once in about 6 or 7 runs the program fails to start, and there seems to be no apparent reason for this. Also, my memory seems to drop over time (using a vector in the class). Any ideas?
/*
* Urn.h
*
* Created on: Jan 17, 2014
* Author: edwinrietmeijer
*/
#ifndef URN_H_
#define URN_H_
#include <cstdlib>
#include <vector>
#include <iostream>
class Urn {
private:
int highRand;
int loRand;
int numsTotal;
int numsLeft;
std::vector<int>numsAvailable;
public:
Urn();
int getRand();
int getSize();
void reset();
virtual ~Urn();
};
#endif /* URN_H_ */
/*
* Urn.cpp
*
* Created on: Jan 17, 2014
* Author: edwinrietmeijer
*/
#include "Urn.h"
using namespace std;
Urn::Urn() : highRand( 9 ), loRand( 0 ) {
vector<int>::iterator pos;
int newRandom;
numsTotal = highRand - loRand;
bool newRandomExists = false;
while ( numsAvailable.size() < numsTotal + 1 )
{
do {
newRandomExists = false;
newRandom = ( rand() % ( numsTotal + 1 ) ) + loRand;
for ( pos = numsAvailable.begin(); pos != numsAvailable.end(); pos++ ) {
// cout << *pos << " ";
if ( *pos == newRandom ) {
newRandomExists = true;
}
}
// cout << " Random -> " << newRandom << " " << newRandomExists << endl;
} while ( newRandomExists == true );
newRandomExists = false;
numsAvailable.push_back( newRandom );
}
cout << endl;
// List the list
for (pos = numsAvailable.begin(); pos != numsAvailable.end(); pos++ ) {
// cout << *pos << " ";
}
// cout << endl;
// TODO Auto-generated constructor stub
}
int Urn::getRand() {
vector<int>::iterator pos = numsAvailable.begin();
int numToReturn = numsAvailable.back( );
numsAvailable.erase( pos );
return numToReturn;
}
int Urn::getSize() {
return numsAvailable.size();
}
void Urn::reset() {
}
Urn::~Urn() {
// TODO Auto-generated destructor stub
}
//============================================================================
// Name : UniqueRand.cpp
// Author : Edwin Rietmeijer
// Version :
// Copyright : This code is owned by Edwin Rietmeijer as of 2014
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
#include <string>
#include "Urn.h"
using namespace std;
int main() {
cout << "Seeding..." << endl;
srand( time( NULL ) );
cout << "Getting object..." << endl;
Urn * urnObject = new Urn;
cout << urnObject -> getRand();
return 0;
}

Undefined reference to a method in another class file, how to fix?

I've been working on a program that will do a couple of equations in regards to audio, SPL, etc.
I decided to have the main class file present the user with an option to choose what equation he wants to do, while the equations are housed in another class file.
Atm, the main class file is setup just to test maxPeakSPL(), yet I can't get it to run.
main.cpp
//Kh[a]os
#include "equations.h"
#include <iostream>
void mainLoop();
int maxSPL = 0;
int main()
{
std::cout << "Created by Kh[a]os" << std::endl << std::endl;
mainLoop();
return 0;
}
void mainLoop()
{
std::cout << "hi";
maxSPL = equations::maxPeakSPL();
std::cout << std::endl << maxSPL << "db" << std::endl << std::endl;
}
equations.h
#ifndef EQUATIONS_H
#define EQUATIONS_H
#include <string>
class equations
{
public:
equations();
static int maxPeakSPL();
protected:
private:
};
#endif // EQUATIONS_H
equations.cpp
#include "equations.h"
#include <iostream>
#include <string>
equations::equations()
{
}
static int maxPeakSPL()
{
int Sens = 0;
double Distance = 0;
int Watts = 0;
int sWatts = 2;
int eWatts = 0;
double maxSPL = 0;
double counter = 0;
double wall = 0;
std::string corner = "";
bool v = true;
std::cout << "Sensitivity (db): " << std::endl;
std::cin >> Sens;
std::cout << "Amplification (watts): " << std::endl;
std::cin >> Watts;
std::cout << "Listening Distance (meters): " << std::endl;
std::cin >> Distance;
std::cout << "Distance from Wall (ft): " << std::endl;
std::cin >> wall;
std::cout << "Are you they in a corner? (y/n): " << std::endl;
std::cin >> corner;
maxSPL = Sens - (Distance*3 - 3);
while(v == true)
{
if (sWatts > Watts)
{
v = false;
eWatts = sWatts;
sWatts = sWatts/2;
Watts = Watts-sWatts;
counter = (double)Watts/(double)eWatts;
counter = counter*3;
maxSPL = maxSPL + counter;
}
if (v == true)
{
maxSPL = maxSPL + 3;
sWatts = sWatts*2;
}
}
if (wall <= 4)
maxSPL = maxSPL + 3;
if (corner == "Y" || corner == "YES" || corner == "y" || corner == "yes")
maxSPL = maxSPL + 3;
return maxSPL;
}
The error I get when I run it is: undefined reference to `equations::maxPeakSPL()'
I haven't a clue how to fix this, any assistance would be great. Thank you.
In your main, try putting the function before the main block. Include an underscore before the name of your directives/flags.

Printing a singly linked list using classes

I am making a program for singly linked lists using multiple files and classes.
I have to have a Node.h, LinkedList.h, Node.cpp, LinkedList.cpp, and a main.cpp
I was having other problems but now my printList() function just prints "List()" instead of "List(node 1, node2, etc...)"
I think my insert might be the problem because my searchNode() doesn't work right either, it always says node not found.
Here is the code I have: (I can't change the Node.h and LinkedList.h files)
Node.h:
//
// Node.h
// Linked Lists
//
#ifndef Linked_Lists_Node_h
#define Linked_Lists_Node_h
class Node
{
public:
Node(int data);
int data;
Node *next;
};
#endif
LinkedList.h:
//
// LinkedList.h
// Linked Lists
//
#ifndef Linked_Lists_LinkedList_h
#define Linked_Lists_LinkedList_h
#include "Node.h"
class LinkedList
{
private:
Node *head;
public:
LinkedList();
void addNode(int data);
void removeNode(int data);
bool searchNode(int data);
void printList();
};
#endif
Node.cpp
//
// Node.cpp
// Linked Lists
//
#include <iostream>
#include <cstdlib>
#include "LinkedList.h"
#include "Node.h"
using namespace std;
Node::Node(int data) {};
LinkedList.cpp
//
// LinkedList.cpp
// Linked Lists
//
#include <iostream>
#include <cstdlib>
#include "LinkedList.h"
#include "Node.h"
using namespace std;
LinkedList::LinkedList()
{
head = NULL;
}
void LinkedList::addNode(int data)
{
Node *newNode;
newNode->data = data;
newNode->next = NULL;
Node *tmp = head;
if(tmp != NULL)
{
while(tmp->next != NULL)
{
tmp = tmp->next;
}
tmp->next = newNode;
}
cout << "Node added" << endl;
printList();
}
void LinkedList::removeNode(int data)
{
Node *tmp = head;
if(tmp == NULL)
{
cout << "No node removed" << endl;
return;
}
if(tmp->next == NULL)
{
delete tmp;
head = NULL;
}
else
{
Node *previous;
do
{
if(tmp->data == data)
{
break;
}
previous = tmp;
tmp = tmp->next;
}
while(tmp != NULL);
previous->next = tmp->next;
delete tmp;
}
cout << "Node removed" << endl;
printList();
}
bool LinkedList::searchNode(int data)
{
Node *tmp = head;
while(tmp != NULL)
{
if(tmp->data == data)
{
cout << "Node found" << endl;
printList();
return true;
}
tmp = tmp->next;
}
cout << "Node not found" << endl;
printList();
return false;
}
void LinkedList::printList()
{
Node *tmp = head;
if(tmp == NULL)
{
cout << "List()" << endl;
return;
}
if(tmp->next == NULL)
{
cout << "List(" << tmp->data << ")";
}
else
{
do
{
cout << "List(" << tmp->data;
cout << ", ";
tmp = tmp->next;
}
while (tmp != NULL);
cout << ")" << endl;
}
}
main.cpp
//
// main.cpp
// Linked Lists
//
#include <iostream>
#include <cstdlib>
#include "LinkedList.h"
#include "Node.h"
#include "LinkedList.cpp"
using namespace std;
int main ()
{
LinkedList list;
int data;
int choice;
while(1)
{
cout << " Select:" << endl;
cout << "1 to add a node" <<endl;
cout << "2 to remove a node" << endl;
cout << "3 to search for a node" << endl;
cout << "4 to exit" << endl;
cout << endl;
cin >> choice;
switch(choice)
{
case 1: //insertion
cout << "Enter node: ";
cin >> data;
list.addNode(data); //add a node
break;
case 2: //deletion
cout << "Enter node: ";
cin >> data;
list.removeNode(data); //remove a node
break;
case 3: //search
cout << "Enter node: ";
cin >> data;
list.searchNode(data); //search for a node
break;
case 4:
exit(0); //exit the program
break;
default: //default case
cout << "Please enter a valid choice (1 - 4)!" << endl;
break;
}
}
return 0;
}
If you could help me figure out my problem I would greatly appreciate it.
You're not adding any nodes. If head is NULL, your add Node becomes:
void LinkedList::addNode(int data)
{
Node *newNode;
newNode->data = data;
newNode->next = NULL;
Node *tmp = head;
if(tmp != NULL)
{
//this never gets executed
}
cout << "Node added" << endl;
printList();
}
You need to treat this case (first insertion):
void LinkedList::addNode(int data)
{
Node *newNode;
newNode->data = data;
newNode->next = NULL;
Node *tmp = head;
if(tmp != NULL)
{
while(tmp->next != NULL)
{
tmp = tmp->next;
}
tmp->next = newNode;
}
else
{
head = newNode;
}
cout << "Node added" << endl;
printList();
}
This will create the head if it doesn't exist already.
Are you using a debugger? It would be much easier (for you) if you did.