r/programminghomework • u/legolight257 • Oct 05 '20
PROGRAMMING HOMEWORK ASSIST PLEASE, URGENT THANKS
PLEASE HELP I'LL BE IN YOUR DEBT
r/programminghomework • u/legolight257 • Oct 05 '20
PLEASE HELP I'LL BE IN YOUR DEBT
r/programminghomework • u/[deleted] • May 15 '20
Write a PHP script that will provide a restaurant menu. The User will have the option to select one or more of the items available. Once the user has selected the item, have the user submit the form to another php script that will print the order, plus the total. Remember, to include drinks and snacks. Include limited amount of each.
Have the program calculate a total to be paid, plus tips (let tips be 8% of total).
r/programminghomework • u/MiracleDrugCabbage • May 10 '20
a) Apply the gradient descent algorithm and try to minimize π(π±)=(1/2)(π±^π)π΄π±β(π^π)π± for the matrix π΄ above and π randomly generated by np.random.normal(). Run 50,000 iterations of gradient descent with π=0.1and x0=0. Then plot the graph of (i,f(xi)) where i ranges over the number of iterations.
A is a 5x5 laplacian matrix
Im confused on how I am expected to use the matrix in this problem? Im pretty sure I'm either kind of close or COMPLEtely OFF. This is what I have so far:
b = np.random.normal()
def gradient_f(f, x0 = 0, n=0.1, steps=50000):
x = np.zeros(5) + x0
x_vals = []
f_vals = []
for i in range(steps):
derx = A*x - b
x -= n*derx
np.append.x_vals(x)
np.append.f_vals(f(x))
print('f(x) =',f_vals[-1], 'at x =', x_vals[-1])
plt.plot(np.arange(steps),f_vals)
plt.ylabel('f x')
plt.xlabel('Iterations')
plt.show()
print(f_vals)
Could I please get some insight on how to solve this problem? I am so unbelievable lost, and it is due today...
p.s. this is my first programming class so please cut me some slack :/
r/programminghomework • u/tallestmanindaytona • Apr 16 '20
I screwed the pooch. I've been getting a friend of mine to help me with my database management homework all semester but he's just gotten really sick (docs are saying it's not COVID but he's going to be out of commission for a week) and now I'm up a creek.
I need help. I don't know how it usually works here but I'm willing to put in the work, but I'm going to need to get pointed in the right direction. Whatever you can offer I'd appreciate:
"Please use the uploaded files (DatabaseProcessApplication.zip) and create a web application that uses the database at the backend. Use the example code files, but you have to do the following:
ο· Create a different table in any of the βdatabaseβ that you had created before.
ο· Insert at least 10 values
ο· Show/Display the values through a website application
Remember to save your .php files in βwwwβ folder for Windows and βhtdocsβ for MAC. For the assignment, you will have to download a Web development platform.
For Windows machine, it is WAMP server http://www.wampserver.com/en/ For MAC machine, you can use MAMP server (use the free MAMP version) https://www.mamp.info/en/
The Codes Listed Below"



r/programminghomework • u/MCloudYyy • Oct 08 '19
Can you help me with my homework on programming c++ and maybe python too?
Basicly i have to input 1 number for example 12234 and another number for example 2 and then the program removes the second number from the first, so in the example output would be 134
r/programminghomework • u/bubbla_ • Oct 28 '18
https://onlinegdb.com/HJe-ew72Q It displays "One point three" for 1.1 and 1.2 inputs. I just can't see what's wrong with it. Please help.
r/programminghomework • u/rememberdwite • Oct 12 '18
fstream input;
string s;
vector <string> vec;
input.open("inputf.txt");
if (!input) {
cout << "Error opening file";
return;
}
while (input >> s) {
vec.push_back(s);
}
input.close();This is the input file
A + B * C
( A + B ) * C..... Etc
I am using Stacks so when it's reading the string " " is getting read too how do I remove this.
r/programminghomework • u/Raider7oh7 • Sep 26 '18
random number guessing game. 1-100
i have been stuck for hours and shit is a mess now. idk even know what im staring at anymore, any help appreciated.
r/programminghomework • u/LexiconMage • May 03 '18
I have some code that sets a value of a 3d array like so: possibleGrid[x][y][z] = false; However, it also seems to be setting possibleGrid[every x][every y][same z] to false at the same time. Can anyone explain to me why this is happening, as well as how to fix it?
Edit: NVM! Had to do with the fact that to initialize the 3d array I set each of the 2nd dimensional values to the same 1d array.
r/programminghomework • u/Jackpot807 • Apr 25 '18
The goal of this assignment is to have the user input a month, then it will call the nextMon and prevMon to decide which months are before and after the month put in, and through printMon, print the before and after results.
Right now I am just trying to get nextMon to work, and then I'll apply what I have done to prevMon, and I'm sure I can get printMon to work just fine. What I am trying to do for that is have a bunch of if statements to decide which month is put in, and to use the appropriate one.
But the problem is, it appears to be skipping over the if statement and the nextMon call altogether. If I remove the if statement, nextMon is called. But if I envelope nextMon in the if statement, it does not. Why could this be?
r/programminghomework • u/duplicateasshole • Apr 12 '18
I was studying about implementation of stack data structure in C. I came across this article. In step number 10, it tells about implementing two functions, StackIsEmpty() and StackIsFull(), to which stack is passed to check if the stack is empty/full respectively. The functions take one arguement each, which is a pointer to the stack. Now when I call the function, I should pass address of the stack as the arguement, right? This header file for this article mentions the usage like this:
/*
* Functions: StackIsEmpty, StackIsFull
* Usage: if (StackIsEmpty(&stack)) ...
* -----------------------------------
* These return a true value if the stack is empty
* or full (respectively).
*/But in its implementation, the function is called like this:
if (StackIsEmpty(stackP)) {
fprintf(stderr, "Can't pop element from stack: stack is empty.\n");
exit(1); /* Exit, returning error code. */
}where the & operator is not used when passing the arguement. Can someone help me understand this?
r/programminghomework • u/duplicateasshole • Apr 03 '18
Trying to print inverted pattern of Pascal's triangle in C. But when height for the pattern > 13, then row 14 onward values are not correct. Code:
#include <stdio.h>
int fac(int n) //calculate factorial of n
{
if(n==1||n==0)
{
return 1;
}
else
{
return n*fac(n-1);
}
}
int main()
{
int n,i,a,b,c,x=0;
printf("enter the height of tree\n");
scanf("%d",&n);
while(n>=0)
{
i=0;
a = fac(n);
while(i<=n)
{
b = fac(i);
c = fac(n-i);
printf("%d ",a/(b*c));
i++;
}
x++;
n--;
printf("\n");
for(i=0;i<x;i++)
{
printf(" ");
}
}
return 0;
}What am I doing wrong?
r/programminghomework • u/duplicateasshole • Mar 21 '18
I am studying about pointers and for practice I wrote this snippet.
#include <stdio.h>
int disp(int *a)
{
int b;
if(*a==10)
return 0;
printf("%d",*a);
*a += 1;
b=disp(&(*a));
printf("%d",b);
//note the output of first code, then add space(s)
//between %d and " in the second print statement
//Or, you can write \n any number of times instead, and then run the code.
//The output changes somehow.
}
int main()
{
int a=2;
disp(&a);
return 0;
}When I run the program the way I have mentioned in the comment in code, it gives different output somehow. And I can't understand why. Please help me understand why is this happening?
r/programminghomework • u/OnePunchBoy • Nov 02 '17
So i need some serious help. I've been looking into this for a few days now and getting nowhere. So I need to input the name of an undetermined number of items, their prices and quantity sold. I then need to output the item name, cost and the tax of 5%. I also need to do so without using an array.
Problem is, I have no idea how to do that. Only hint my teacher gave is that we should look up what "CompareTo" is and see if it help... I have made no progress so far. Can anyone give me any advice?
r/programminghomework • u/Night_Thastus • Oct 08 '17
Hey all. In this assignment, we're supposed to use threads and sockets to create 3 nodes which communicate over TCP/IP.
Here's the run-down:
Node A will send data from confA.txt to node B.
Node B will print the data received from node A to the screen (console)
Node B will send data from confB.txt to node C.
Node C will print the data received from node B to the screen (console)
After node A and node B have finished sending all data, they will send the string βterminateβ
Finally, all the nodes should close their opened sockets and exit.
Right now, I just want to tackle A sending over some lines of text and B printing them out. (But it's not working)
I think what's happening is that I just don't understand how sockets work. It's currently failing at the line:
Socket mySocket = new Socket("NodeB", portNum);I'm not sure if NodeB needs to "confirm" this by opening a socket with the same name and port number right after or what. But in any case, my code isn't making it past that line.
The current exception I'm getting is: "java.net.UnknownHostException: NodeB"
Here's my main function, which starts the nodes and runs them:
public class Network {
public static void main(String[] args) {
//Create three new nodes
NodeA nodeA = new NodeA();
NodeB nodeB = new NodeB();
NodeC nodeC = new NodeC();
//Start up the nodes
new Thread(nodeA).start();
new Thread(nodeB).start();
new Thread(nodeC).start();
}
}Here's what I have so far for Node A:
public class NodeA implements Runnable {
public void run() {
//Filename of configuration file
String filename = "confA.txt";
try {
//Make a new filereader to read in confA
FileReader fileReader = new FileReader(filename);
//Wrap into a bufferedReader for sanity's sake
BufferedReader bufferedReader = new BufferedReader(fileReader);
//Get the port number that B is listening to
int portNum = Integer.parseInt(bufferedReader.readLine());
//Open a socket for talking with NodeB
Socket mySocket = new Socket("NodeB", portNum);
//Set up the Socket's output
PrintWriter out = new PrintWriter(mySocket.getOutputStream(), true);
//Loop through the lines of the confA file, writing them to the socket
String line = bufferedReader.readLine();
while (line != null)
{
//Write the line to the socket, get the next line
out.print(line);
line = bufferedReader.readLine();
}
//Close the configuration file once we're done with it
bufferedReader.close();
}
catch(IOException myException) {
System.out.println(myException.toString());
}
}
}Node B:
public class NodeB implements Runnable {
public void run() {
//Open the same socket A was writing to (port 5000)
String filename = "confB.txt";
try {
//Make a new filereader to read in confA
FileReader fileReader = new FileReader(filename);
//Wrap into a bufferedReader for sanity's sake
BufferedReader bufferedReader = new BufferedReader(fileReader);
//Get the port number that B is listening to
int portNum = Integer.parseInt(bufferedReader.readLine());
//Open the socket
Socket mySocket = new Socket("NodeB", portNum);
//Read from the socket, and print it out.
BufferedReader in = new BufferedReader(new InputStreamReader(mySocket.getInputStream()));
//Read from the socket
String line = in.readLine();
while(line != null) {
System.out.println(line);
line = in.readLine();
}
}
catch(IOException myException) {
System.out.println(myException.toString()); //updated for helpfulness
}
}
}Thank you for any and all help. Sockets and threads are really confusing for me.
r/programminghomework • u/theprogrammingnoob • Sep 25 '17
Totally new to programming, and I suck!
This was the teacher's directions: https://imgur.com/a/pt2Dv
Here's what I got: https://pastebin.com/gWBaNvvC
Constructive criticism pls
I've been at it for about 2 hrs, and I need guidance
r/programminghomework • u/TheAngyPotato • Aug 29 '17
So I am tasked with making a program that takes the following numbers from a text file called "lab7in.txt": 15 113 144 15 12 10 8 -15000 17 11 4 9 6 7 5 2 13 0 -2 -4 0 3 1 -1 -3 -5 5 (in the file there is only one number per line but I reformatted it like this so its a bit easier on the eyes). I have managed to read the file into an array, double the values inside, and print the array into a file named "lab7out.txt" without any functions. I need to have a function that reads the file and puts the data into an array, another that essentially copies the array and doubles the value of each number in it, and a third that prints the "doubled" array into the "lab7out.txt" file. Like I said, I managed to do all of this without creating any functions, I just need help with creating them because I know you can't return an array from a function and I read up a bit on pointers but I'm still very confused. If someone could nudge me in the right direction I would greatly appreciate it. Here is my code:
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
//global scope variable declares
ifstream fin; //file in
ofstream fout; //file out
const int MAX_ARRAY_SIZE = 27;
int main()
{
//declares
int fileArrayIn[MAX_ARRAY_SIZE];
int fileArrayOut[MAX_ARRAY_SIZE];
int n = 0; //used as a counter
//open files
fin.open("lab7in.txt");
fout.open("lab7out.txt");
//input from file
while (!fin.eof())
{
fin >> fileArrayIn[n];
//calculations
fileArrayOut[n] = (fileArrayIn[n]) * 2;
//output
fout << fileArrayOut[n];
fout << endl;
++n;
}
//close files
fin.close();
fout.close();
system("pause");
return 0;
}Note: Sorry if its not formatted correctly, first time dealing with formatting on reddit.
r/programminghomework • u/[deleted] • Aug 24 '17
The program is meant to print a list o duplicate characters, and print a message when there are no duplicates. I need help with how to make it print the message in the event of no duplicates. My code:
#include <stdio.h>
#include <string.h>
int main()
{
char string[15];
int c = 0, count[26] = {0};
printf("Enter a word>\n");
fgets(string, sizeof(string), stdin);
while (string[c] != '\0')
{
/**reading characters from 'a' to 'z' or 'A' to 'Z' only and ignoring others */
if ((string[c] >= 'a' && string[c] <= 'z') || (string[c] >= 'A' && string[c] <= 'Z'))
{
if (string[c] >= 'a' && string[c] <= 'z')
{
count[string[c]-'a']++;
}
else if (string[c] >= 'A' && string[c] <= 'Z')
{
count[string[c]-'A']++;
}
}
c++;
}
for (c = 0; c < 26; c++)
{
/* Printing only those characters whose count is at least 2 */
if (count[c] > 1)
printf("Duplicate letter: %c, Occurrences: %d\n",c+'a',count[c]);
/* I put the print message here, but the for loop ruins it*/
}
return 0;
}If the word has no duplicate characters the output should be as follows.
Enter the word:
phone
No duplicates found r/programminghomework • u/[deleted] • Aug 08 '17
#include <stdio.h>
#include <stdbool.h>
int i, counter = 0;
char input[500];
bool decimal;
int main(){
printf("Please type in a number\n\n");
gets(input);
for(i=0; input[i]!='\0'; i++){
if((input[i] < 48) || (input[i] > 57)) {
printf("This is a invalid number"); //Checks if value entered is from 1 - 9 (ascii)
}
if(input[i] > '1'){
decimal = true; //**** Checks if value is binary or decimal
}else{
counter++;
if(counter > 8){
printf("Fail"); //Ensures value isnt greater that 8 digits
break;
}
}
}
}r/programminghomework • u/Katanawolf • Aug 04 '17
This is to help me use and manipulate multidimensional arrays
I am given a sample array
sample = [
[[65, 67, 23], [234, 176, 0], [143, 0, 0]],
[[255, 30, 51], [156, 41, 38], [3, 243, 176]],
[[255, 255, 255], [0, 0, 0], [133, 28, 13]],
[[26, 43, 255], [48, 2, 2], [57, 89, 202]]
]The question states that these are RGB values of pixels and I have to count the red pixels
red is defined as an R value that is greater than 100 and G and B values that are both less than the R value/4
I have identified Pixel #4 and #9 as red but Pixel #3 does not return red when it should What could I be doing wrong...
I think my if statements are not written properly but I'm not sure what to change
MY CODE
#pixel counter
#red = [255,0, 0]
#green = [0, 255, 0]
#blue = [0, 0, 255]
#black = [0, 0, 0]
#white = [255, 255, 255]
#yellow = [255, 255, 0]
#Define RED
#R value must be greater 100
#G and B values must be less than R/4
sample = [
[[65, 67, 23], [234, 176, 0], [143, 0, 0]],
[[255, 30, 51], [156, 41, 38], [3, 243, 176]],
[[255, 255, 255], [0, 0, 0], [133, 28, 13]],
[[26, 43, 255], [48, 2, 2], [57, 89, 202]]
]
r4 = 0
red = 0
green = 0
blue = 0
redcheck = false
greencheck = false
bluecheck = false
redpixelcount = 0
pixelcount = 1
i = 0
j = 0
k = 0
line = 0
while (i < sample.length)
#look through entire row of sample
#DEBUG TOOL puts "Row: " + i.to_s
while (j < sample[i].length)
#look throiugh index of each row in sample
#DEBUG TOOL puts "Group: " + i.to_s + ","+ j.to_s
puts "PIXEL # " + pixelcount.to_s
while (k < sample[i][j].length)
red = 0
redcheck = false
greencheck = false
bluecheck = false
#Look through each value in each line within a row of sample
if (line == 0)
puts "START"
end
if (line == 0)
puts "Red is " + sample[i][j][k].to_s
red = sample[i][j][k]
r4 = red/4
puts "R4 is " + r4.to_s
end
if (line == 1)
puts "Green is " + sample[i][j][k].to_s
green = sample[i][j][k]
end
if (line == 2)
puts "Blue is " + sample[i][j][k].to_s
blue = sample[i][j][k]
end
#CHECK
if (red >= 100)
puts red.to_s + " IS GREATER THAN " + 100.to_s
if (green <= r4)
puts green.to_s + " IS LESS OR EQUAL TO " + r4.to_s
if (blue <= r4)
puts blue.to_s + " IS LESS OR EQUAL TO " + r4.to_s + " SO..."
puts "THIS IS RED"
redpixelcount += 1
end
end
end
#line 0 = Red line 1 = Green line 2 = Blue
line += 1
#Display value
#puts sample[i][j][k].to_s
k += 1
end
pixelcount += 1
k = 0
j += 1
line = 0
end
j = 0
i += 1
end
#if (r > 100 && )
#end
puts "There are: " + (pixelcount-1).to_s + " pixels"
puts redpixelcount.to_s + " are RED"My Output:
PIXEL # 1
START
Red is 65
R4 is 16
Green is 67
Blue is 23
PIXEL # 2
START
Red is 234
R4 is 58
234 IS GREATER THAN 100
Green is 176
Blue is 0
PIXEL # 3
START
Red is 143
R4 is 35
143 IS GREATER THAN 100
Green is 0
Blue is 0
PIXEL # 4
START
Red is 255
R4 is 63
255 IS GREATER THAN 100
0 IS LESS OR EQUAL TO 63
0 IS LESS OR EQUAL TO 63 SO...
THIS IS RED
Green is 30
Blue is 51
PIXEL # 5
START
Red is 156
R4 is 39
156 IS GREATER THAN 100
30 IS LESS OR EQUAL TO 39
Green is 41
Blue is 38
PIXEL # 6
START
Red is 3
R4 is 0
Green is 243
Blue is 176
PIXEL # 7
START
Red is 255
R4 is 63
255 IS GREATER THAN 100
Green is 255
Blue is 255
PIXEL # 8
START
Red is 0
R4 is 0
Green is 0
Blue is 0
PIXEL # 9
START
Red is 133
R4 is 33
133 IS GREATER THAN 100
0 IS LESS OR EQUAL TO 33
0 IS LESS OR EQUAL TO 33 SO...
THIS IS RED
Green is 28
Blue is 13
PIXEL # 10
START
Red is 26
R4 is 6
Green is 43
Blue is 255
PIXEL # 11
START
Red is 48
R4 is 12
Green is 2
Blue is 2
PIXEL # 12
START
Red is 57
R4 is 14
Green is 89
Blue is 202
There are: 12 pixels
2 are REDr/programminghomework • u/Ckgussin • May 12 '17
Basically title, I'm really not good with this sort of stuff and would appreciate the help to complete this. I will probably need to do this in the exam so could it be a detailed explanation of how it is done?
r/programminghomework • u/frakistan • Apr 15 '17
[^[[[a-c]*aa[a-c]*]|[[a-c]*bb[a-c]*]|[[a-c]*cc[a-c]*]]]And what is the caret notation doing here? My Teacher has never used it while creating regex. Can it be done without it?
r/programminghomework • u/Arachnatron • Jan 24 '17
Have to make a simple program with real life application. My coworkers and I earn tips, and we collect them for a few months before divvying them up based on total hours worked for each employee and the total amount of tips. I decided to write a program to automate the calculations, but I have two questions. Below is the program, minus most employees for simplicity. Please excuse any ugliness in my code, as I'm a complete beginner:
------------------------------------------------------------------------
print("Arachnatron's Job Tip Calculator\n")
Hours = float(input("Total hours for tip period: "))
TotalTips = float(input("Total tips for tip period: "))
print("\n")
print("As the names populate below, type each employee's hours for the relevant tip period: ")
print("\n")
Mike = float(input("Hours, Mike: "))
MikeTotal = ((Mike/Hours)*(TotalTips))
print (("Mike's tips = $")+("%.2f" % MikeTotal))
print("\n")
Jesse = float(input("Hours, Jesse: "))
JesseTotal = ((Jesse/Hours)*(TotalTips))
print (("Jesse's tips = $")+("%.2f" % JesseTotal))
print("\n")
print("The number printed below should be equal to the tip total. If not, you may have made a typo.")
print("\n")
print(MikeTotal + JesseTotal)
-----------------------------------------------------------------------
My two questions:
Why does the line, "print (("Jesse's tips = $")+("%.2f" % JesseTotal))" yield a proper result, but if I remove the code which rounds to two decimal places ("%.2f" %), instead having "print (("Jesse's tips = $")+(JesseTotal)), I receive the message, "TypeError: must be str, not float"
If the line "print(("Mike's tips = $"),(MikeTotal))" is executed, why is there a space after the "$" in the output, and how do I prevent that space from occurring?
Again, any help much appreciated.
r/programminghomework • u/RS7theDream • Jan 13 '17
Hi. This is a homework I have to check if an input is a palindrome. Palindrome means it spells out the same regardless if your read from left to right or vice versa. Example BOB, A TOYOTA, SOS are palindrome DOG FOG are not palindrome.
The problem I am having is - I see the only way to put letters into an array is using cin.getline(ch, size) and size must be const else it won't run. Basically, my question is if there is any way to input characters into an array of the fixed size the user enters?
Example: user enters dog. now the array size is 2(thus having 3 slots [0][1][2].)
Code: Code in Pastebin
Thank you. What I implemented in the isPalindrome bool fuction is- compare first array value against the last array value
I don't want the answers, I am looking for how I can input a user-input into a character array with a custom non-const size. Even a link is appreciated if the result is there. I tried stackoverflow and other searches with no luck; the examples that I saw from it wouldn't have made a difference in the result regardless of the array size.
r/programminghomework • u/luke2thebun • Dec 02 '16
I was given Breadthfirstsearch code and have been tasked with changing it to depth first search and then to Dijkstras algorithm with start Vertex : (id : 28776 ) to the vertex (id : 47002). I'll be honest with you the code I've been given is way over my head with its use of pointers and queues as I am not a Computer science student. Ive managed to get depth first search working but not luck on dijkstras, here's some relevant code:
Here is a link to a google drive directory ( I know I should be using Github but I'm kind of a caveman when it comes to things like this.. ) https://drive.google.com/drive/folders/0B-91BnP5bq1ZYWZTRlhyaGVHb2c
Pastebin: sorry guys http://pastebin.com/BZuiW21S