moshimoshi
moshimoshi
Explore posts from servers
CC#
Created by moshimoshi on 4/19/2023 in #help
❔ Help needed to fix ASP.NET syntax errors
Hi all, I'm currently doing a project for ecommerce site, and have encountered multiple bugs while debugging and have been stuck on it as i'm not sure how to fix them.
The issue is with the check out page, the quantity toggle buttons work ok but the trash can to delete each row and 'remove all' button which deletes everything in the cart at the top doesnt work. when i tried debugging, these are the errors shown (Apologies if context is not set very clear as i am super new to ASP.NET):
cart.js?v=Ms174dTiHCVhvUXchgzzipQGl6qy_xRKYaz8GGYX9u4:31 Uncaught ReferenceError: carts is not defined
at removeAll (cart.js?v=Ms174dTiHCVhvUXchgzzipQGl6qy_xRKYaz8GGYX9u4:31:14)
at HTMLUnknownElement.onclick (CartList:69:70)
removeAll @ cart.js?v=Ms174dTiHCVhvUXchgzzipQGl6qy_xRKYaz8GGYX9u4:31
onclick @ CartList:69
cart.js?v=Ms174dTiHCVhvUXchgzzipQGl6qy_xRKYaz8GGYX9u4:26 Uncaught ReferenceError: carts is not defined
at removeRow (cart.js?v=Ms174dTiHCVhvUXchgzzipQGl6qy_xRKYaz8GGYX9u4:26:14)
at HTMLImageElement.onclick (CartList:103:215)
cart.js?v=Ms174dTiHCVhvUXchgzzipQGl6qy_xRKYaz8GGYX9u4:31 Uncaught ReferenceError: carts is not defined
at removeAll (cart.js?v=Ms174dTiHCVhvUXchgzzipQGl6qy_xRKYaz8GGYX9u4:31:14)
at HTMLUnknownElement.onclick (CartList:69:70)
removeAll @ cart.js?v=Ms174dTiHCVhvUXchgzzipQGl6qy_xRKYaz8GGYX9u4:31
onclick @ CartList:69
cart.js?v=Ms174dTiHCVhvUXchgzzipQGl6qy_xRKYaz8GGYX9u4:26 Uncaught ReferenceError: carts is not defined
at removeRow (cart.js?v=Ms174dTiHCVhvUXchgzzipQGl6qy_xRKYaz8GGYX9u4:26:14)
at HTMLImageElement.onclick (CartList:103:215)
13 replies
CC#
Created by moshimoshi on 4/17/2023 in #help
❔ Running ASP.NET file in Rider
7 replies
CC#
Created by moshimoshi on 4/14/2023 in #help
❔ Dependency injection & inheritance
There are 2 classes - tours and tour package. I'm planning to use dependency injection on an instance of tours into tour package. Does it mean that I'll be able to inherit its attributes too? Why/ whynot?
10 replies
CC#
Created by moshimoshi on 3/27/2023 in #help
✅ Binary Search Tree
2 replies
CC#
Created by moshimoshi on 3/23/2023 in #help
✅ Finding node in binary search tree
Hi can someone help me understand the syntax of this code - I am struggling with understanding why we need to define the instance of current node in the iterative method but dont need to do so in the recursive method. Thanks! 🙂
//Recursive
public Node? Find(int key) {
// Base Case: Current node is null
if (this == null)
return null;

// Base Case: Current node is the key
if (this == key)
return this;

if (this < key) {
return this.right.Find(key);
}

else return this.left.Find(key);
}

//Iterative
public Node? Find(int key)
{
Node current = this;

while (current != null) {

if (current == key) {
return current;
}

else if (current < key) {
return current.right;
}

else (current > key) {
return current.left;
}
}

return null;
}
//Recursive
public Node? Find(int key) {
// Base Case: Current node is null
if (this == null)
return null;

// Base Case: Current node is the key
if (this == key)
return this;

if (this < key) {
return this.right.Find(key);
}

else return this.left.Find(key);
}

//Iterative
public Node? Find(int key)
{
Node current = this;

while (current != null) {

if (current == key) {
return current;
}

else if (current < key) {
return current.right;
}

else (current > key) {
return current.left;
}
}

return null;
}
1 replies
CC#
Created by moshimoshi on 3/23/2023 in #help
✅ Heaps & Priority Queue
What is priority queue in heap data struct?
9 replies
CC#
Created by moshimoshi on 3/19/2023 in #help
✅ Algorithm analysis
Can someone help me understand how we got this formula to calculate time efficiency from this code?
sum = 0
loop i from 1 to n
loop j from 1 to i
sum = sum + 1
sum = 0
loop i from 1 to n
loop j from 1 to i
sum = sum + 1
this is the formula: f(n) = n2/2 + n/2, which is O(n2) The formula goes like this, 1 + 2 + 3 + 4 + ... + N but i have no idea how to connect the dots. Thanks!
17 replies
CC#
Created by moshimoshi on 3/15/2023 in #help
✅ Why wont these SQL queries work?
Creating a userview - this works.
CREATE VIEW GoodCustomer
AS SELECT CustomerID, CustomerName,
MemberCategory,CountryCode
FROM Customers
WHERE MemberCategory IN (‘A’,’B’)
CREATE VIEW GoodCustomer
AS SELECT CustomerID, CustomerName,
MemberCategory,CountryCode
FROM Customers
WHERE MemberCategory IN (‘A’,’B’)
Update userview - doesnt work
UPDATE GoodCustomer
SET MemberCategory = ‘C’
WHERE CustomerID = 1000
UPDATE GoodCustomer
SET MemberCategory = ‘C’
WHERE CustomerID = 1000
Insert userview: - doesnt work
INSERT INTO GoodCustomer (CustomerID,
MemberCategory, CountryCode)
VALUES ( ‘5000',’C’, ‘USA' )
INSERT INTO GoodCustomer (CustomerID,
MemberCategory, CountryCode)
VALUES ( ‘5000',’C’, ‘USA' )
5 replies
CC#
Created by moshimoshi on 3/9/2023 in #help
❔ accessing mdb files on macOS
does anyone know how to access mdb files on macOS? I have installed dockers and microsoft azure data studio for SQL
2 replies
CC#
Created by moshimoshi on 2/26/2023 in #help
❔ inheritance??
Is this an inheritance problem statement? Im not sure how to implement it... You are tasked with designing a database for an online radio station. The database should keep track of songs, their artists, their length in seconds, and the number of times they have been played. It should also keep track of the names of the radio stations that the songs have been played on. Your program should be able to perform the following operations: Add a song to the database. A song should have a title, an artist, a length in seconds, and the number of times it has been played. Add a radio station to the database. A radio station should have a name. Add a playlist to the database. A playlist should have a name and a list of songs. Add a song to a playlist. Print the total length of a playlist in a human-readable format (hours, minutes, seconds). Print the total number of times that a song has been played. Print a list of all songs that have been played on a given radio station. Print a list of all songs that have been played on multiple radio stations. Print a list of all artists that have had songs played on a given radio station. Print a list of all songs that are longer than a given length in seconds. The program should be written in C# using object-oriented programming principles, with appropriate classes and inheritance relationships. The code should be well-structured, readable, and maintainable.
2 replies
CC#
Created by moshimoshi on 2/23/2023 in #help
❔ Polymorphism
Can someone help me understand this part of the code? I dont understand why its being written like this...
public class BankBranch
{
//
// This field keep a list of bank accounts.
// Any type of accounts will be accepted
//
private List<Account> _accounts;

public BankBranch(string name)
{
Name = name;
_accounts = new List<Account>();
}

// Auto-properties
public string Name { get; set; }
public class BankBranch
{
//
// This field keep a list of bank accounts.
// Any type of accounts will be accepted
//
private List<Account> _accounts;

public BankBranch(string name)
{
Name = name;
_accounts = new List<Account>();
}

// Auto-properties
public string Name { get; set; }
14 replies
CC#
Created by moshimoshi on 2/22/2023 in #help
❔ use of args in method
can someone explain the specific context in which we declare args in the methods? e.g. for this method - no args are declared whereas for another mtd where new variables are introduced, args are declared. Here's code:
public bool TransferTo(double amount, Account another)
{
bool isWithdrawOk = Withdraw(amount);

if (isWithdrawOk)
{
another.Deposit(amount);
return true;
}
else return false;
}
public bool TransferTo(double amount, Account another)
{
bool isWithdrawOk = Withdraw(amount);

if (isWithdrawOk)
{
another.Deposit(amount);
return true;
}
else return false;
}
public void CreditInterest()
{
var interest = CalculateInterest();
Deposit(interest);
}
public void CreditInterest()
{
var interest = CalculateInterest();
Deposit(interest);
}
47 replies
CC#
Created by moshimoshi on 2/15/2023 in #help
❔ Classes and objects
Hi guys, I need help solving this problem: Write a class to model a Lamp. Provide the following methods in your class: a) turnOn – turn ON the lamp b) turnOff – turn OFF the lamp c) showCurrentColor – outputs current color of lamp Each time the lamp is turned ON, it shows a different color. The changing color-sequence is Red, Green, Blue, then loops back to Red and so on. The state of the lamp is initially OFF. When the lamp is turned ON for the first time, its color should be Red. Note that the lamp cannot be turned ON if it is already ON. Its state needs to be OFF before a call to turnOn() has any effect. Test that your lamp exhibits the correct color-changing order by turning it ON and OFF 10 consecutive times. I am stuck here, not sure how to proceed...
namespace ColourLamp;

public class Lamp
{
//Attributes
public bool IsOn;
public string Color;

//Initializing
public Lamp(string Color)
{
IsOn = false;
this.Color = Color;
}

//Methods
public string ShowCurrentColor()
{

for (int i = 0; i <= 10; i++)
{
for (int j = 1; j <= 2; j++)
{
if (SwitchArray[i][0])
return "Red";
if (SwitchArray[i][1])
return "Green";
if (SwitchArray[i][2])
return "Blue";
}
}
}

public bool IsLampOn()
{
return IsOn;
}

public void TurnOn()
{
if (! IsLampOn())
IsOn = true;
}

public void TurnOff()
{
if (IsLampOn())
IsOn = false;
}
}
namespace ColourLamp;

public class Lamp
{
//Attributes
public bool IsOn;
public string Color;

//Initializing
public Lamp(string Color)
{
IsOn = false;
this.Color = Color;
}

//Methods
public string ShowCurrentColor()
{

for (int i = 0; i <= 10; i++)
{
for (int j = 1; j <= 2; j++)
{
if (SwitchArray[i][0])
return "Red";
if (SwitchArray[i][1])
return "Green";
if (SwitchArray[i][2])
return "Blue";
}
}
}

public bool IsLampOn()
{
return IsOn;
}

public void TurnOn()
{
if (! IsLampOn())
IsOn = true;
}

public void TurnOff()
{
if (IsLampOn())
IsOn = false;
}
}
16 replies
CC#
Created by moshimoshi on 2/14/2023 in #help
❔ Matrix Multiplication
6 replies
CC#
Created by moshimoshi on 2/14/2023 in #help
❔ Understanding guidelines around use of 'bool'
Hi folks, i need help understanding the usage of bool before a loop. I've looked at the way some people write their code, sometimes bool is made equals to true and sometimes false. Are there certain guidelines for this?
12 replies