mardi 28 juin 2016

Print Quadruple Precision vector in C++ [duplicate]

I'm trying to print a quadruple precision vector using GCC 4.7.1 in CodeBlocks. This is the code:

#include <iostream>
#include <vector>
#include <quadmath.h>

...

int width = 46;
char buf[128];
for (std::vector<__float128>::const_iterator i = sol_r.begin(); i != sol_r.end(); ++i)
{
    int n = quadmath_snprintf (buf, sizeof buf, "%+-#*.20Qe", width, *i);
    if ((size_t) n < sizeof buf)
    {
        std::cout << buf << ' ';
    }
}

I get this error: undefined reference to 'quadmath_snprintf(char*, unsigned int, char const*, ...)'. What am I doing wrong?


Concerning the duplicate claim, the answer indicated as duplicate contains indeed part of the solution, but it is a general question including several different problems.

Users having problems in printing a quadruple precision vectors are most probably inexperienced (as I am) and would benefit more from a more concise answer and/or more precise sources.

The question asked here can be solved by checking out:

https://gcc.gnu.org/ml/gcc-help/2011-06/msg00148.html (add header as extern)

What is an undefined reference/unresolved external symbol error and how do I fix it? (link the relevant library as libquadmath)

Xcode 7.3.1 - Can't properly setup AWS

A year ago I had a project where I was using AWS. I forget exactly how it worked but it involved a BridgingHeader and no use of Frameworks.

I came back to this project today and none of the AWS stuff was working. I deleted all AWS/pod related files, got rid of the BridgingHeader reliance, cleaned the project, and proceeded to follow the pod-based instructions here:

http://docs.aws.amazon.com/mobile/sdkforios/developerguide/setup.html

However, the project still doesn't recognize any of the AWS libraries (getting the error "Use of unresolved identifier AWS...").

I saw a post by someone that suggested simply putting "import Framework" at the top of the files that use that Framework, but this doesn't work (it doesn't recognize AWSS3 when I put "import AWSS3", for example).

Then I saw advice that suggested figuring out the correct "Framework/Header/Library Search Paths" and so I created a brand new project, copied the podfile, and ran pod install. In this new project I am getting the error:

ld: warning: directory not found for option '-F/Users/username/Library/Developer/Xcode/DerivedData/TestProj-gmhzshcpuyuvaffaocakhunyepaw/Build/Products/Debug-iphonesimulator/AWSAutoScaling'

for each of the AWS libraries.

When I go into the target build settings, I see that the Framework Search Paths have strings relating to the AWS libraries, but when I delete them I then get the error "ld: Framework not found AWSAutoScaling".

I tried giving the direct path to the respective folders but I get the same error.

Qt .5.7 issue with QMessangeLogger and QList<int>

I was making a program which will conver text to pixel image and I occured some problems while trying to compile the code.

First problem is with QMessangeLogger:

C:QtQt5.7.05.7mingw53_32includeQtCoreqlogging.h:158: błąd: expected ',' or ';' before 'QMessageLogger'
 #define qDebug QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC).debug 

When I'm double clicking on it, it takes me back to one of Qt's main files.

Second problem is with Qt list:

 F:GraphicalCrypterGraphicalCrypterencryptmy.cpp:46: błąd: cannot convert 'QList<int>' to 'int' for argument '1' to 'constexpr QRgb qRgba(int, int, int, int)'
             value = qRgba(intArray[index-3], intArray[index-2], intArray[index-1],intArray[index]);

Here is my code :

//encryptmy.cpp http://pastebin.com/mnLqNHAy

//encryptmy.hpp http://pastebin.com/qyhYE9v7

//main.cpp

#include <QApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include "encryptmy.h"

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    QQmlApplicationEngine engine;
    enCryptMy enryptmy;
    engine.rootContext()->setContextProperty("enCryptMy", &enryptmy);
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    return app.exec();
}

The QList error is appearing in line 46 in my file (link to pastebin). And the first one appears in qlogging.hpp in line 158. Just for sure, I have not changed anything in this file.

What is wrong with this code? I've tried several methods to fix those error but none helped.

Thanks in advance!

Trying to connect Facebook login via FirebaseUI Auth but having an issue with authUI.delegate = self

I am attempting to connect Facebook login via FirebaseUI Auth however I cannot get the Facebook connect button to appear in the instanced authViewController. Platform: iOS, Language: Swift 2.0, Latest stable Xcode release

Everything is working as it should as far as pulling up an instanced authViewController. The e-mail/password option is present and actively creates a new user in my Firebase database.

The problem I am having occurs when trying to implement Facebook login functionality;

In my AppDelegate.swift file I have the following:

import Firebase
import FirebaseAuthUI
...
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

    FIRApp.configure()
    let authUI = FIRAuthUI.authUI()!
    authUI.delegate = self

    return true
}

The error I'm getting is "Cannot assign value of type 'AppDelegate' to type 'FIRAuthUIDelegate'" - basically I can't get the following line to work; authUI.delegate = self

I have read all documentation and browsed open/closed issues on implementation at the project's gitHub repo here: https://github.com/firebase/FirebaseUI-iOS/tree/master/FirebaseUI

I have looked over a previous StackOverflow question that is similar in nature here; How to use FirebaseUI for Google authentication on iOS in Swift?

I have attempted to copy the code from the above Stack Overflow since he states he did get more options to appear using his code (his question is about an error further down the line regarding authentication) but I still run into the same self delegation error. I have tried assigning FIRAuthUIDelegate to AppDelegate but it does not conform. What am I missing?

QuickSort in C++ will not finish sorting

Could someone please help me and tell me why quick sort algorithm will not sort the final element? When I input: 6 89 2 78 12 19 99 43 7 63 I get an ALMOST sorted: 2 6 7 12 78 19 43 99 63 89

I have tried to figure this out my self, but when I work my way thought the code at some point I get lost doing a desk check.

#include <iostream>
using namespace std;

// function prototypes
void quickSort(int arrayList[], int left, int right);
int choosePivot(int arrayList[], int listSize);
int partition(int array[], int left, int right);
void printArray(int theArray[], int Size);
// void swap(int value1, int value2);

int main()
{
    int myList[] = {6, 89, 2, 78, 12, 19, 99, 43, 7, 63};
    printArray(myList, 10);
    quickSort(myList, 0, 9);
    printArray(myList, 10);

    //int myList2[] = { 7, 4, 9, 10, -9 };
    //printArray(myList2, 5);
    //quickSort(myList2, 0, 5);
    //printArray(myList2, 5);


    cin;
    getchar;
    getchar;

    return 0;
}


void quickSort(int arrayList[], int left, int right)
{
    //if (left < right)
    if(right > left)
    {
        int p = partition(arrayList, left, right);

        printArray(arrayList, 10);
        quickSort(arrayList, left, p-1);
        quickSort(arrayList, p + 1, right);
    }
}

// left (index value) - left most part of the array we are working on
// right (index value) - right most part of the array we are working on
int partition(int array[], int left, int right)
{
    //int pivot = array[left]; // I will have to write a function to find the
    //  optimum pivot point, this is the naive solution
    int pivot = array[(left+right)/2];


    int i = left;
    int j = right;
    int temp;
    while (i < j)
    {
        //cout << "in the loop" ;
        while (array[i] < pivot)
            i++;
        while (array[j] > pivot)
            j--;
        if (i < j)
        {
            temp = array[i];
            array[i] = array[j];
            array[j] = temp;
            i++;
            j--;
        }
    }

    return i;
}

void printArray(int theArray[], int Size)
{
    for (int i = 0; i < Size; i++)
    {
        cout << theArray[i] << " ";
    }
    cout << endl ;
}

UITableView Delegate Method not getting called?

I' m trying to extract the UITableView Delegate method into a base class called BaseTableProvider

//BaseTableProvider.h
@protocol RSTableProviderProtocol <NSObject>

- (void)cellDidPress:(NSIndexPath *) atIndexPath;

@optional
- (void)cellNeedsDelete:(NSIndexPath *) atIndexPath;

@end

@interface RSBaseTableProvider : NSObject <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) NSMutableArray *dataSource;
@property (nonatomic, weak) id<RSTableProviderProtocol> delegate;

@end
//BaseTableProvider.m
@implementation RSBaseTableProvider
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [[UITableViewCell alloc]init];
    return cell;
}
@end

And then I create a subclass of BaseTableProvider, and override two UITableViewDelegate Method in the subclass

//RSFeedListTableProvider.h
@interface RSFeedListTableProvider : RSBaseTableProvider

@end

//RSFeedListTableProvider.m
@implementation RSFeedListTableProvider

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return [self.dataSource count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    RSFeedCell *cell = (RSFeedCell *)[tableView dequeueReusableCellWithIdentifier:kFeedCell];

    if(cell == nil){
        cell = [[RSFeedCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:kFeedCell];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }

    Feed *feed = (Feed *)self.dataSource[indexPath.row];

    if (feed != nil) {
        cell.titleText = feed.title;
        cell.subTitleText = feed.summary;
    }


    return cell;
}

@end

I initialized the ListTablerProvider in a ViewController.

//RSFeedListViewController.m
@implementation RSFeedListViewController

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    _feedListView = [[RSFeedListView alloc] init];

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    _provider = [[RSFeedListTableProvider alloc] init];
    _provider.delegate = self;

    return self;
}

#pragma mark -- Life Cycle

- (void)loadView{
    RSFeedListView *aView = [[RSFeedListView alloc] initWithFrame:[UIScreen mainScreen].bounds];

    self.feedListView = aView;
    self.view = aView;

    self.feedListView.tableView.delegate = _provider;
    self.feedListView.tableView.dataSource = _provider;
}

But I can't see the cell built on the screen.I debuged the code found that UITableView Delegate Method in RSFeedListTableProvider was not called.Any one can help me?Thanks!

C++ beginner - trying to write a function but getting a identifier...is undefined

I am a student and am tasked with creating a program that will determine if a person is rich or not. My code is below and I keep getting an error that identifier "isRich" is undefined. Can someone help me figure out where I went wrong?

EDIT assignment instructions removed, since the error is in the syntax, not the logic

#include "stdafx.h"
#include <iostream> //for input and output
#include "Cusick Project 5.h"
using namespace std;


void calcWealth(int age, long cash, int dependants, long debt)
{

cout << "Please enter your age: ";
cin >> age;
cout << "Please enter the amount of cash on hand: ";
cin >> cash;
cout << "Please enter the amount of dependents you have: ";
cin >> dependants;
cout << "Please enter the amount of money you owe";
cin >> debt;

bool isRich(int *age, long *cash, int *dependants, long *debt);
{
    long trueCash;
    bool status = false;

    trueCash = cash - debt;

    if (dependants == 0)
    {
        if (trueCash >= 1000000)
        {
            status = true;
        }
        else
            status = false;
    }

    else if (age < 40)
    {
        trueCash = trueCash - (dependants * 150000);
        if (trueCash >= 1000000)
        {
            status = true;
        }
        else
            status = false;
    }

    else if (age > 39 && age < 51)
    {
        trueCash = trueCash - (dependants * 75000);

        if (trueCash >= 1000000)
        {
            status = true;
        }
        else
            status = false;
    }

    else
    {
        trueCash = trueCash - (dependants * 25000);

        if (trueCash >= 1000000)
        {
            status = true;
        }
        else
            status = false;
    }
  }
}

int main()
{
    int age;
    long cash;
    int dependants;
    long debt;
    bool status; 

    cout << "Welcome to the wealth indicator..." << endl;

    calcWealth(age, cash, dependants, debt);

    if (isRich(status) = true)
    {
        cout << "Congratulations!  We consider you as being "rich."" <<     endl;
    }

    else
    {
        cout << "I am sorry!  You are not yet "rich."" << endl;
    }
}