Hello I have a homework question and although I'm not looking for someone to answer this for me, a guide would be appreciated from senior programmers here.

A disc can transfer only one 512 byte block with each access. Student records are 80 bytes longs, are to be organized into hash buckets. How many records should each bucket contain?

Thanks!

Hello, I'm working on an assignment right now and I need some feedback. My project is to implement a graph that uses an adjacency list like an Edge list. I'm fairly new with these and I would apprecite if anyone can see my code if I'm on the right track. Thanks!

#include<iostream>
#include<string>
#include<list>
using namespace std;

#define D true
#define U false
#define W true
#define N false
#define MAX 100

class Edge 
{
public:
    Edge() 
    {
    }
    Edge(int from, int to, double weight = -1) 
    : from (from), to (to), weight (weight)
    {
    }
    Edge(const Edge & other) 
    {
        from = other.from;
        to = other.to;
        weight = other.weight;
    }
    Edge & operator=(const Edge & other) 
    {
        this->from = other.from;
        this->to = other.to;
        this->weight = other.weight;
        return *this;
    }
    int operator== (const Edge & other) const 
    {
        if (this->from != other.from) return 0;
        if (this->to != other.to) return 0;
        if (this->weight != other.weight) return 0;
        return 1;
    }
    int from;
    int to;
    bool directed;
    double weight;
};

class Graph 
{
public:
    Graph(int n, bool directed, bool weighted)
        : directed(directed), weighted(weighted)
    {
    }
    void addEdge(Edge e) 
    {
        list<Edge> adjList;
        adjList.push_back(e);   
    }
    bool isDirected() 
    {
        return directed;
    }
    bool isWeighted() 
    {
        return weighted;
    }
    int getNumVertices ();
    int getNumEdges ();
private:
    bool directed;
    bool weighted;
    Edge *adjList;
};

int main() {
    Graph a(8, U, N); 
    Edge a0(0, 1);
    Edge a1(1, 3);
    Edge a2(6, 3);
    Edge a3(4, 5);
    Edge a4(1, 2);
    Edge a5(3, 7);
    Edge a6(3, 4);
    a.addEdge(a0);
    a.addEdge(a1);
    a.addEdge(a2);
    a.addEdge(a3);
    a.addEdge(a4); ...

Hello, I need some advice on how this function outputs the left zeros so everything will be even at 16 bits

[CODE]string conv (int num, int base) {
if (num == 0)
return "0000000000000000";

char NUMS[] = "0123456789ABCDEF";
string result = "";

do {
    result.push_back (NUMS[num % base]);
    num /= base;
} while (num != 0);

return string (result.rbegin(), result.rend());

}[/CODE]

Current Output:
100111110101

GOAL:
0000100111110101

Thanks in advance!

Thanks! I will check on this.

Thanks fr the quick response guys, but I forgot to mention that this line is preset by my instructor:

[CODE]sample x = {"Dude", {1., 2., 3., -5.}, 4};[/CODE]

So I can't separate the {1., 2., 3., -5.} from the line. Any tips? Thanks again!

thank you, but I was instructed to only use dynamic arrays in a struct so i don't want to limit it to just 4 elements, it coulb be 2 or 1000. so the only thing i'm thinking is by a pointer. any tips?

best regards,

I'm having an error "a value of type "double" cannot be used to initialize an entity of type "double *"

Any tips? Thanks!

[CODE]#include

include

using namespace std;

struct sample {
string name;
double *num;
unsigned elements;
};

int main () {
sample x = {"Dude", [COLOR="Red"]{1, 2, 3, -5}[/COLOR], 4};

}

[/CODE]

This is code btw,

[CODE]#include

include
include

int main()
{
std::string token, text("M 36 John Doe Mary F 45");
std::istringstream iss(text);
while ( getline(iss, token, '') )
{
std::cout << token << std::endl;
}
return 0;
}[/CODE]

But all of them are still strings, I want to set each one as data type appropriate.

Thank you, but my problem is I have to anticipate that the user might enter the data on a different format like:

M 36 John Doe Mary F 45

Any tips? Thanks again!

Hello, what's the best way to sort a string to ints & chars. For example:

"John Doe M 36"

to
John Doe (char[])
M (char)
36 (int)

I researched about istreamstring sin(), but I'm not yet fully familiar with it, any tips. Thanks!

Oh I got it now, my program is now bug-free. Thanks for the help guys.

I'm sorry I don't fully understand your question. Well what holds the stack is the stack.parens[stack.elements] if that's what you meant?

I will try those advices. BTW, it seems that my top() is not working properly. Its function is to show the top on the stack, what's the best way to write it or to improve my code? THanks!

We covered a basic class lessons last semester. I will give that a try. Question, where is the debug output option? It seems that my bug is somewhere in the for loop at main.

Hi, I'm writing a program that checks parens/brackets/braces if they are paired. Tha catch is I have to write my own stack functions, this is my code so far, it used to work when I was working with just the parentheses, now that I added more options it's not working and now I'm lost, any expert advice or tips from a second pair of eyes? Thanks in advance.

BTW, did I write my initialize() and top() functions correctly?

Thanks again!

[CODE]/
This little program checks to see whether the left and right
parentheses / brackets / braces
characters are properly mathed and nested in a line of text.
/

include
include

using namespace std;

const unsigned MAX_DEPTH = 4;

struct charStack {
char *paren;
unsigned elements;
} stack;

bool die ( const string& );
void initialize ( charStack& );
bool full ( const charStack& );
bool empty ( const charStack& );
void push ( charStack&, char );
char pop ( charStack& );
char top ( charStack& );
bool isOpen (char);
char isClose (char);
bool balance ( charStack& );

int main () {
string line;
bool ok = true;
initialize ( stack );
cout << "Type a string: ";
if ( !getline ( cin, line ) ) die ( "can't input string." );
for ( unsigned i = 0; i < line.size(); i++ ) {
if ( isOpen(line[i]) )
push( stack, line[i] );
else if ( line[i] = isClose(line[i]) ) {
if ( empty ( stack ) ) { ...

Wow thanks guys for the tips!

Good day to all, I'm doing a project about inverse permutations from an array of permutations. It's my first time coding on permutations so I don't have any experience on this. So I came up with a solution to just swap the array and the element number as the inverted permutation. Here's my code by the way, I'm just wondering if the "seasoned" members here have any tips on doing an inverted permutation properly.

Please let me know if you guys have any advice. Thanks!

[CODE]void inverse ( unsigned ip[], const unsigned p[], unsigned elements ) {
unsigned tempArray = 0, tempIndex = 0;
for (int i = 0; i < elements; i++ ) {
tempIndex = i;
tempArray = p[i];
ip[tempArray] = tempIndex;
}
show ( ip, 5 );
}[/CODE]

Thanks so much, now I have another question, im still sorting the blank spaces but for some reason it's not doing what's it supposed to.

my goal is to ignore all spaces and just save the int, but the first digit is always iterated. THanks again.

SAMPLE
Enter an arithmetic query in this format: [INT] [OPERAND] [INT]
[I][2 spaces[/I]] [B]12[/B] [I][2 spaces][/I][B] 34[/B]
[B]2[/B] and [B]4[/B]
Press ENTER for another calculation, or press Q to quit program.

[CODE]printf ("Enter an arithmetic query in this format: [INT] [OPERAND] [INT]\n");

    while (((ch = getchar()) == ' ') && (ch != '\n')) {
            blank++;
        }
    while (((ch = getchar()) != ' ') && (ch != '\n')) {
            if (my_isDigit(ch)) {
                first = first * 10 + (ch - '0');
            }
        }
    while (((ch = getchar()) == ' ') && (ch != '\n')) {
            blank++;
        }
    while (((ch = getchar()) != ' ') && (ch != '\n')) {
            //if (!my_isDigit(ch)) error (1);
            second = second * 10 + (ch - '0');
        }

    printf ("%d and %d\n", first, second);[/CODE]

Hello, I'm making a simple C calculator using only getchar and putchar functions, my program works only if the arithmetic is entered correctly but if it's not, I can't make the proper error checking on it if the arithmetic is enteres improperly.

EXAMPLE:

4 + 7 = 11 =====> Works!
7 * -3 = -21 =====> Works!

4 [2spaces] + [3spaces] 7 =====> Won't error check.
% 5 =====> Won't error check.
4 * =====> Won't error check.

Any suggestions please? Thanks!

[ICODE]/*

include
include
include

void error (int), add (int, int, bool, bool),
subtract (int, int, bool, bool),
multiply (int, int, bool, bool),
mod (int, int, bool, bool),
divide (int, int, bool, bool);

int main(void)
{
int ch = 0, first = 0, second = 0, op = 0, next = 0;
bool firstIsNeg = false, secondIsNeg = false;
char operand = 0;

printf ("Enter an arithmetic query on this format: [int] [operand] [int]\n");

while (((ch = getchar()) != ' ') && (ch != '\n'))
{
    if (ch == '-'){ 
        firstIsNeg = true;
        ch = 0;
    }
    else if (!isdigit (ch)) 
        error(1);
    else if (ch == ' ') next = 1;
    else    
        first = first * 10 + (ch - '0');
}

while (((ch = getchar()) != ' ') && (ch != '\n') && (next = 1))
{
    if (ch == 43) operand = '+';
    if (ch == 45) operand = '-';
    if (ch == 47) operand = '/';
    if (ch == 42) operand = '*'; ...

oh i never realized that! thank you!

Hello, I'm starting to learn Java and this one of my homework but for some reason it won't run. My algorithm is to just add all 1-1000. I highlighted the part that's causing a problem in red. Please help, thanks!

[CODE]
import java.util.*;
public class thousand
{
static final Scanner in = new Scanner ( System.in );
public static void main(String[] args)
{
int n = 1000;
int total = [COLOR="Red"]n/COLOR/2;
System.out.println ("%i" + total);
}
}
[/CODE]

This is the error code:
[CODE]
thousand.java:10: cannot find symbol
symbol : method n(int)
location: class thousand
int total = n(n+1)/2;
^
1 error
[/CODE]

ahh thank you so much! I missed that part. I forgot storage on line 8!

Thanks again!

I wrote this string palindrome program that reads input from a text file. All the syntax are correct but I have an error I couldn't understand. Any help is appreciated, thanks!!!

First, this is the error message:

[B]Error 1 error LNK2001: unresolved external symbol "char * newToCheck"
(?newToCheck@@3PADA)[/B]

And this...

[B]Error 2 error LNK1120: 1 unresolved externals[/B]

This is my code so far:

[CODE]

include
include

using namespace std;

const int strSize = 0xFF;
ifstream infile;
char checkPhrase[strSize], origPhrase[strSize], newToCheck[];
int cleanup (char, int), newCount;
bool palindrome (char
, int, int);

int main()
{
infile.open ("C:\Documents and Settings\student\Desktop\PalindromeData.rbh");

if (!infile)
{
    cout << "File not found.  Check your directory and/or file and try again.\n\nEnter any key to exit..." << endl;
    cin.get();
    exit(1);
}

while (!infile.eof())
{
    infile.getline(origPhrase, sizeof(checkPhrase));
    for (int i = 0; i < strSize; i++)
        checkPhrase[i] = origPhrase[i];
    newCount = cleanup (checkPhrase, strlen(checkPhrase));
            newToCheck [newCount];
    for (int n = 0; n < newCount; n++)
        newToCheck[n] = checkPhrase[n];
    if (palindrome (newToCheck, 0 , newCount - 1)) 
        cout << "The phrase " << origPhrase << " is a Palindrome\r\n.";
    else 
        cout << "The phrase " << origPhrase << " is not a Palindrome\r\n.";
}

infile.close();
cin.get();
return 0;

}

int cleanup (char* phrase, int size)
{
int currentChar = 0;
for(int i = 0; i < size; i++)
{
if(((int)phrase[i] >= 48 && (int)phrase[i] <= 57) || ((int)phrase[i] >= 65 && (int)phrase[i] <= 90) || ((int)phrase[i] >= 97 && (int)phrase[i] <= 122))
{
phrase[currentChar] = tolower(phrase[i]);
currentChar++;
}
} ...

That didn't work. This started happening after I installed NVDIA drivers.

When I click on any of my menu bar, the menu wont expand or sometimes it does but missing some. I tried reinstalling and resetting it but it still doesn't work. Please help. Thanks.

I attached a print screen of the problem.

Sorry about that. What I meant is the data is not storing properly (goes to endless loop)and the output looks like this:

Error on number of Adults data.Error on number of Children data.Error on Meal type data.Error on weekend dataError on number of Adults data.Error on number of Children data.Error on Meal type data.Error on weekend dataError on number of Adults data.Error on number of Children data.Error on Meal type data.Error on weekend dataError on number of Adults data.Error on number of Children data.Error on Meal type data.Error on weekend dataError on number of Adults data.Error on number of Children data.Error on Meal type data.Error on weekend dataError on number of Adults data.Error on number of Children data.Error on Meal type data.Error on weekend dataError on number of Adults data.Error on number of Children data.Error on Meal

Hello, I'm trying to create a program that reads data from outside file using functions. My goal is to get data from an outside file, and use that data for other functions that i havent created yet. this is my code so far but it wont read and giving me output errors.

PLease help, thanks so much!

[CODE]

include
include
include
include

using namespace std;

ifstream infile;
ofstream outfile;
int noOfAdults, noOfKids;
float deposit;
string mealType;
bool weekend;

void getData ();

int main()
{

infile.open ("C:\\Users\\garu525\\Desktop\\CateringDatafile.rbh");
if (!infile)
{
    cout << "File not found.  Exiting. . ." << endl;
    exit(1);
}

outfile.open ("C:\\Users\\garu525\\Desktop\\CateringBill.rbh");

while (!infile.eof())
{
    getData ();
}
cout << fixed << showpoint << setprecision(2);
cout << noOfAdults << '\t' << noOfKids << '\t' << mealType << '\t' <<weekend << '\t' << deposit << endl;    

infile.close();
outfile.close();
system ("pause");
return 0;

}

void getData ()
{
infile >> noOfAdults >> noOfKids >> mealType >> weekend >> deposit;
cout << noOfAdults << noOfKids << mealType << weekend << deposit;

if (noOfAdults < 0 || (!infile)) outfile << "Error on number of Adults data.";
if (noOfKids < 0 || (!infile)) outfile << "Error on number of Children data.";
if (mealType != "S" || "D") outfile << "Error on Meal type data.";
if (mealType == "S") mealType = "Standard";
if (mealType == "D") mealType = "Deluxe";
if (!weekend) outfile << "Error on weekend data";
if (deposit < 0) outfile << "Error on Deposit data";

}
[/CODE]

Thank you!

Here's my code so far. I got what I wanted it works so far, except the minimum number on my line 1 output.

Here's my output file:

Numbers on line 1:
346 130 982 90 656 117 595
Highest number is: 982
Lowest number is: [B][COLOR="Red"]-858993460[/COLOR][/B] Should be 90
Sum = 2916
Average = 416.571

Numbers on line 2:
415 948 126 4 558 571 87
Highest number is: 948
Lowest number is: 4
Sum = 2709
Average = 387

Numbers on line 3:
42 360 412 721 463 47 119
Highest number is: 721
Lowest number is: 42
Sum = 2164
Average = 309.143

Numbers on line 4:
441 190 985 214 509 2 571
Highest number is: 985
Lowest number is: 2
Sum = 2912
Average = 416

Numbers on line 5:
77 81 681 651 995 93 74
Highest number is: 995
Lowest number is: 74
Sum = 2652
Average = 378.857

Numbers on line 6:
310 9 995 561 995 93 74
Highest number is: 995
Lowest number is: 9
Sum = 3037
Average = 433.857

Numbers on line 7:
466 664 892 8 766 34 639
Highest number is: 892
Lowest number is: 8
Sum = 3469
Average = 495.571

Numbers on line 8:
151 64 98 813 67 834 369
Highest number is: 834
Lowest number is: 64
Sum = 2396
Average = 342.286

[CODE]

include
include
include

using namespace std;

int main()
{
ifstream infile;
ofstream outfile;
int num[7], min, ...

Thank you FBody and vdit X, I will try both your suggestions.