Undermine 31 Light Poster

Which version of Hibernate are you using?

3.2.5 Hibernate

and Spring 3.0.2

Undermine 31 Light Poster

Hello guys, I am using Hibernate + Spring with netbeans to make a web application. I have it working correctly and displaying data from the DB. My problem is I only know how to do one hibernate query which is shown below.

How can I do insert/delete queries. For instance in my JSP page I have a button, how can I make it so when a user clicks on a button it deletes a specific record from the database. In essence how can I pass parameters to my controller. and can someone explain when/how I need to use DAO objects.

Thanks!

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package controller;

import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.HibernateUtil;
import org.hibernate.Session;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

/**
 *
 * @author Zombies
 */
public class TestimonialsController implements Controller {

    public ModelAndView handleRequest(HttpServletRequest hsr, HttpServletResponse hsr1)
        throws Exception
    {


        ModelAndView bc = new ModelAndView("testimonials");
        String out = new String ("testimonial list");



        try {
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            session.beginTransaction();
            List result= session.createQuery("from Testimonial").list();
            bc.addObject("testimonials", result);
            session.getTransaction().commit();
        } catch (Exception e) {
            e.printStackTrace();
        }

        bc.addObject("message", out);
        return bc;
        }


  }
Undermine 31 Light Poster

that's dumb.

what if he wants to add 9999 as one of his numbers

Cool thanks for coming in offering no valuable input of your own just destructive criticism. If choosing 9999 is a problem he could use a different sent value it's just a suggestion.

Moron.

Undermine 31 Light Poster

I would do something different and use a sentinel value to terminate input. Loop until users stops the loop.

int value, count=0, sum=0, total;
    
    for(;;) // out forever loop
    {
        for(;;) // 
        {
            cout << "Enter value " << count+1 << ": ";
            value = -9999;
            cin >> value;
  
        
          
            cin.clear();
            cin.sync();

            if ( value == -9999 ) { cout << "Bad data entry ... "; continue; }
            if ( value ==  9999 ) break; // break out of inner loop
            
++count;

total= sum += value;
average= total/count;         
                       
                      
    
           
        } // end of inner forever loop ...
        
        if (value == 9999 ) break; // break out of outer loop
      
   
    
    } // end of outer forever loop ...
Undermine 31 Light Poster

Hello i'm rather new to Python and I was wondering how I could do a menu to prompt the user to choose a number and execute a certain part of code based on his choice.

For example:

please choose an option
1)
2)
3)

then based on users input, it executes only that part of the code.

Would i just do something like

if choice ==1 :
do this

if choice ==2:
do this

ect?

Undermine 31 Light Poster

got it thanks for the help

Undermine 31 Light Poster

did that still not printing out even or odd

Undermine 31 Light Poster

hi, im trying to learn python and this is giving me

>>> x=input("Enter a value: ")
if x % 2 ==0:
print ("even")
else:
print ("odd")

then when i execute:


Enter a number:

then i enter a number but it does not print even or odd. why?

Undermine 31 Light Poster

Make sure you have the Ming compiler, and put the Dev c++ executable and the .cpp file into the same folder.

Then try execute --> rebuild all.

then if still nothing, uninstall and reinstall.

Undermine 31 Light Poster

header

class DeckOfCards
{
      
public:
DeckOfCards();
void Shuffle();
void deal();
void hand();
             
private:
int deck[4][13];
int numcard;
int row;
int col;
                     
                     
                     
                     
};

main

#include "dc.h"

using namespace std;
      
      
int main()
{
DeckOfCards DeckCards;

DeckCards.Shuffle();
DeckCards.deal();
DeckCards.hand();
return 0;

}
#include <iostream>
using std::cout;
using std::cin;
using std::right;
using std::left;
using std::endl;

#include <iomanip>
using std::setw;

#include <cstdlib>
using std::srand;
using std::rand;

#include <ctime>
using std::time;

#include "dc.h"

DeckOfCards::DeckOfCards()
{//being constructor
int numcard=0;
//int row=0;
//int col=0;
for (int row=0; row<=3; row++)
{//begin loop
for (int col=0; col<=12; col++)
{//begin inner loop
    deck[row][col]=0;
}//end inner loop
}//end outer loop
srand(time(0));
}//end

void DeckOfCards::Shuffle()
{//start shuffle
     int row;
     int col;
     for (int card=1; card<=52; card++)
     {
         do
         {
              row=rand()%4;
              col=rand()%13;
              }
              while (deck[row][col] !=0 );
              
              deck[row][col] = card;
              }
            //  hand();
              }

  
void DeckOfCards::deal()
{
     static const char *suit[4]={"Hearts" , "Diamonds" , "Clubs", "Spades"};
     
     
static const char *face[13]= {"Ace", "Two", "three", "four", "five", "six", "Seven", 
"Eight", "Nine", "Ten", "Jack", "Queen", "King"};

for (int card=1; card <= 52; card ++)
{
    for (int row=0; row <=3; row++)
    {
        for (int col=0; col <= 12; col ++)
        {
if (deck[row][col]==card)
{
                         
//cout <<setw(5)<< right << face [ col]<<" of " << setw(8) << left << suit[row] << endl;
cout <<setw(5)<< right << face [col]<<" of " << setw(8) << left << suit[row] << endl;



}
                                
}
}

}
                             
     system("PAUSE");    
}//end shuffle
                  
                 
void DeckOfCards::hand()
{

   // cout << card << endl ;
    //  cout << card << endl ;
     
     
     }

How can …

Undermine 31 Light Poster
//6.12

#include <iostream>
#include <iomanip>

using namespace std;

double CalculateCharges (double car1=1.5,double car2=2.0,double car3=24.0);

int main ()

{




cout<<" Parking Garage Rates " << endl;


cout<<"Car"<<"Hours"<<"Charge"<<endl;

double rate
;
for (int i=1;i<=3;i++)
cout<<i<<" "<<CalculateCharges(rate)<<endl;

cout<<"Total"<<endl;

return 0;

}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


double CalculateCharges(double car1, double car2, double car3)
{
    double hours[3];
     hours[0]=car1;
    hours[1]=car2;
    hours[2]=car3;
    int b;
    for( b = 0; b <= 2; b++ ){
   hours[b] = (hours[0],hours[1],hours[2]);
   }
    double rate;
    
   
   
    for (double h=0;h<=24;h=+hours[b])
    {
    if (h<3)
    rate = 2.00;
    else if (h>3)
    {
    rate = (.50*h);
    }
    else if ( h == 24 )
    {
    rate = 10.00 ;
    }
    
  return rate;  

}
}

Hello I tried to change some things like you said but it still did not work. I am pretty terrible at c++ so if you can explain once again what's wrong that would be super.

The program is supposed to loop 3 times, each time returning a rate based on the value i sent it from the function call at the top. But it's not doing that.. not at all. Each time it loops it's supposed to read the next value in the array.. Though that's not working either.

Undermine 31 Light Poster
//6.12

#include <iostream>
#include <iomanip>

using namespace std;

double CalculateCharges (double car1=1.5,double car2=2.0,double car3=24.0);

int main ()

{




cout<<" Parking Garage Rates " << endl;

cout<<setw(10);
cout<<"Car"<<"Hours"<<"Charge"<<endl;

double car1;
for (int i=1;i<=3;i++)
cout<<i<<CalculateCharges(car1)<<endl;

cout<<"Total"<<endl;

return 0;

}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


double CalculateCharges(double car1, double car2, double car3)
{
    double rate;
    double hours[3];
    hours[0]=car1;
    hours[1]=car2;
    hours[2]=car3;
    int b;
    for( b = 0; b <= 3; b++ ){
   hours[b] = b;
   }
    for (double h=0;h<=24;h=+hours[b])
    {
    if (h<=3)
    rate = 2.00;
    else if (h>=3)
    {
    rate = (.50*h);
    }
    else if ( h == 24 )
    {
    rate = 10.00 ;
    }
    
    

}
}

So the thing complies, but it does not generate any numbers, or anything like that.. I'm confused.. help.

Undermine 31 Light Poster

You're absolutely right...

I should sacrifice two goats.

Narue commented: Chickens work better in my experience. +31
Undermine 31 Light Poster

Hello, I have a program that's 95% written. I am getting weird results though, so I will need you to fix it and EXPLAIN why that worked.

This should take an experienced programmer less then 30 minutes. I would post it on here, but it's over a thousand lines of code. Simple stuff, arrays and classes, but just too tedious to read through.

If you're interested send me a PM please. TY for your time. I will pay through pay-pal. If this post is against forums rules, my bad and go delete it plz. :(

Undermine 31 Light Poster

Ok i fixed that but now when i run main i get..

#include<iostream>


#include "bj.h"


//-------------------------------------------------------------------

int main(int argc, char *argv[])
{ 
int numCards=0; //to know what card you are on
int deck[52];
Blackjack myBlackjack("welcome to blackjack");

myBlackjack.Shuffle();
myBlackjack.PrintCard(0);
myBlackjack.InitDeck(deck[],52);

//myBlackjack.InitDeck();



system("\nPAUSE");

return 0;
}

variable or field `InitDeck' declared void
'class Blackjack' has no member named 'InitDeck'

/facepalm

Undermine 31 Light Poster

HEADER..

#include <string>
using std::string;
class Blackjack
{
  public:    
           
        Blackjack(string);  
        void Shuffle();
        void Intro(string);
        void InitDeck(Card deck[],int numCards);
        void PrintCard(int);
      //  void Card(int);     
             
             
             
  private:
          
        int deck[52];  //deck of 52 cards.

};

BODY

#include    <iostream>
#include    <fstream>
#include    <cctype>
#include    <cstdlib>
#include    <ctime>
using namespace std;

     
const int       NUM_CARDS = 52;
enum            { Spades, Clubs, Hearts, Diamonds };
enum            { JACK = 11, QUEEN, KING, ACE };


// type definitions
typedef int         SuitType;
typedef int         RankType;
typedef int         ValueType;


// structure declarations
struct  Card
{
    SuitType    suit;
    RankType    rank;
    ValueType   value;
};

#include "bj.h"

Blackjack::Blackjack(string name)
{
    Intro( name );
                      
}
void Blackjack::Intro(string name)
{
cout<<"##############################################################"<<endl;    
cout<<"Program done by" <<  endl;
cout<<"Lets define the basic rules::" << endl;
cout<<"##############################################################"<<endl;
system("PAUSE");


void Blackjack::InitDeck(Card deck[] int numCards)//what each card is

{
    auto    int         deckIndex = 0;
    auto    RankType    rankCounter;
    auto    SuitType    suitCounter;

    for (suitCounter = Spades; suitCounter <= Diamonds; ++suitCounter)
        {
        for (rankCounter = 2; rankCounter <= ACE; ++rankCounter)
            {
            // set the suit and rank members
            deck[deckIndex].suit = suitCounter;
            deck[deckIndex].rank = rankCounter;

            // set the value member
            if (ACE == deck[deckIndex].rank)
                {
                // if we have an ace, assign the highest possible value
                deck[deckIndex].value = 11;
                }
            else if (deck[deckIndex].rank >= JACK)
                {
                // if we have a face card, assign it a value of ten
                deck[deckIndex].value = 10;
                }
            else
                {
                // the rank of the card is its value
                deck[deckIndex].value = deck[deckIndex].rank;
                }
            ++deckIndex;
            }
        }

}  // end of "InitDeck"

MAIN

#include<iostream>


#include "bj.h"


//-------------------------------------------------------------------

int …
Undermine 31 Light Poster

Hey thanks you've been a giant help. 2 more questions while you are here =P

What do i sent the PrintCard from main it is asking for an int value?

and my next function will be to assign value to the cards, the problem is how is it going to refer back to the shuffle and printcard constructors?

Undermine 31 Light Poster

quick problem i get like this:

no match for 'std::operator<< [with _Traits = std::char_traits<char>](((std::basic_ostream<char, std::char_traits<char> >&)(&std::cout)), ((const char*)"human has ")) << ((Blackjack*)this)->Blackjack::PrintCard(((Blackjack*)this)->Blackjack::deck[0])'

note C:\Dev-Cpp\include\c++\3.4.2\bits\ostream.tcc:63 candidates are: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>&(*)(std::basic_ostream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]

and i have absolute 0 idea what that means

Undermine 31 Light Poster

Ok so now the problem becomes that i need to send to printcard whatever value the shuffler comes up with each time it shuffles the deck, how do i do this?

Undermine 31 Light Poster

HEADER FILE:

#include <string>
using std::string;
class Blackjack
{
  public:    
           
        Blackjack(string);  
        void Shuffle();
        void Intro(string);
        void InitDeck();
        void PrintCard(int);
      //  void Card(int);     
             
             
             
  private:
          
        int deck[52];  //deck of 52 cards.

};

BODY PROGRAM.

#include    <iostream>
#include    <fstream>
#include    <cctype>
#include    <cstdlib>
#include    <ctime>
using namespace std;



#include "bj.h"

Blackjack::Blackjack(string name)
{
    Intro( name );
                      
}
void Blackjack::Intro(string name)
{
cout<<"##############################################################"<<endl;    
cout<<"Program done by" <<  endl;
cout<<"Lets define the basic rules::" << endl;
cout<<"##############################################################"<<endl;
system("PAUSE");

}
void Blackjack::Shuffle()
{
//int deck[52];
srand(time(0));

int b;
for( b = 0; b < 52; b++ ){
   deck[b] = b+1;
}

int t;
for (int i=0; i<(52-1); i++)
{
int j = i + (rand() % (52-i));
int temp = deck[i];deck[i]=deck[j];deck[j]= temp;
}

int card1=deck[0];
int card2=deck[1];
int card3=deck[2];
int card4=deck[3];

cout << "human has "<< deck[0] << " " << deck[2]<< endl;
cout<<" computer has" << deck[1] <<" " << deck[3] << endl;

}


void Blackjack::PrintCard(int temp)
 {

	// Print Rank
	const int kiRank = (temp % 13);
	if (kiRank == 0) {
		cout << 'A';
	} else if (kiRank < 9) {
		cout << (kiRank + 1);
	} else if (kiRank == 9) {
		cout << 'T';
	} else if (kiRank == 10) {
		cout << 'J';
	} else if (kiRank == 11) {
		cout << 'Q';
	} else {
		cout << 'K';
	}
	// Print Suit
	const int kiSuit = (temp/13);
	if (kiSuit == 0) {
		cout << 'C';
	} else if (kiSuit == 1) {
		cout << 'D';
	} else …
Undermine 31 Light Poster

Hey stu appreciate the input, but you're code is a little bit over my head. I'm just getting into pointers so i will use it as a reference :)

BTW on my current blackjack program im having trouble resetting the hand after each game, as in the game is over computer won with blackjack, how do i clear hands and reshuffle the deck and redeal.?

Undermine 31 Light Poster

yea... i'm so stupid.. Thanks for that one vmanes.

BTW could you suggest how i should deal out the cards, i need 2 cards for human 2 for computer to start. So should i do a function call to my shuffler to generate 4 random cards or?

Undermine 31 Light Poster

I'm trying to make a shuffler for a blackjack program it's supposed to give me back a random number from a deck of cards each time i call it. But it's also supposed to keep track of cards out of the deck..

I need to make it a function call, but before i do that it's not even working in the first place... it's giving me 51 random crazy numbers..

help please?


#include <iostream>
using std::cout;
using std::cin;
using std::endl;

#include <cstdlib>
using std::rand;
using std::srand;

#include <ctime>
using std::time;

//int random();
int main()
{//begin main
srand(time(0));
int deck[52];
//int random()
//{
for (int i=0; i<51; i++)
{
int j = rand() % (51 - i) + i + 1;
int t = deck[i];
deck[i] = deck[j];
deck[j] = t;
//return t;
//}
cout << t << endl;
}   
//randomize the time

//int cardval = random();


 system("pause");


 return 0;
}//end main
Undermine 31 Light Poster

you are absolutely right, thanks :)

Undermine 31 Light Poster
#include <iostream>
#include <cmath>

using namespace std;

int main()
{//begin main
double hypot(double,double);
double base;
double height;

cout<<"Program to compute the Hypotenuse of a given right triangle. \n"<<endl;
cout<<"Enter the base: \n"<< endl;
cin>>base;
cout<<"Enter the height: \n"<<endl;
cin>>height;
cout <<"The hypothenus of given triangle is " << hypot(base,height) <<endl;

system("pause");

return 0;
}//end main

double hypot(double base, double height)
{//begin function
       
double newb=pow(base,2.0);
double newh=pow(height,2.0);
double newa=newb+newh;
double hyp= pow(newa,.5);

return hyp;
}//end function

[Linker error] undefined reference to `hypot(double, double)'

Why is this happening?