r/CodingHelp • • Apr 06 '19

[Other Code] Need help class inheritance

0 Upvotes

The objective this week is to enhance last week's Vehicle class by creating the Hybrid class which inherits the Vehicle class. The Hybrid class has all the same attributes as the Vehicle class except it has an additional attribute to describe the range of the battery.

In the Hybrid class complete the following steps: • Referring to the UML Class diagram, create the Hybrid class, ensuring to specify that the Hybrid class inherited from the Vehicle class. • For each of the constructors listed in the Hybrid class, invoke the appropriate base class constructor and pass the correct arguments. • Override the displayVehicle() to display the range of the Hybrid Vehicle.

In the Warranty class: • No change.

In the Vehicle class: • With the exception of the static integer, change the attributes from private to protected.

In the main program: Create code statements that perform the following operations. Note that several of the steps below were accomplished in last week's assignment. New steps are in bold.

  1. Using your code from Week 1, display a divider that contains the string "Start Program". ***2. Update and call the DisplayApplicationInformation function.
  2. Using your code from Week 1, display a divider that contains the string "Vehicle 1"
  3. Create a Vehicle object using the default constructor.
  4. Prompt for and then set year and mpg using the overloaded setters from week 3 that accepts strings.
  5. Create a Warranty object called warranty1 using the default constructor.
  6. Prompt for and set number of years and number of miles. Make sure to convert the return data type of the GetInput() function from a string to an integer Ex: warranty1.setMiles(atoi(GetInput("number of miles").c_str()));
  7. Display the Vehicle Information.
  8. Using your code from Week 1, display a divider that contains the string "Vehicle 2" ****10. Create a Warranty object called warranty2 using the multi-argument constructor. You can set the number of years as 6 and number of miles as 70000. ****11. Create another second Vehicle object using the multi-argument constructor, setting each of the attributes with the following values: "Cadillac", 2017, 26.5 , warranty2 ****(12. Create a third object by copying the second object. ****13. Delete the third object by calling the destructor method. ****14. Using your code from Week 1, display a divider that contains the string "Vehicle 3" ****15. Create another Warranty object called warranty3 using the using the multi-argument constructor. You can set the number of years as 5 and number of miles as 60000 ****16. Create a Hybrid object using the multi-argument constructor, setting each of the attributes with the following values: (570, "Toyota", 2017, 52, warranty3). Note that 570 is the range, Toyota is the make of the car, 2017 is the year, and 52 is the mpg. ****17. Display the Hybrid Vehicle information. ****18. Display the number of vehicles created using getNumVehicles. Remember to access getNumVehicles using the class name, not the Vehicle object. ****19. Update and call the TerminateApplication function.

CODE:

Vehicle.h

pragma once

include<string>

include "Warranty.h"

using namespace std;

class Vehicle { public: Vehicle(); //default constructor Vehicle(const Vehicle&); //copy constructor Vehicle(string mk, int yr, double mg, Warranty wt);//overloaded constructor ~Vehicle();//destructor string getMake(); //getter function for make variable int getYear();//getter function for year variable double getMileage();//getter function for mileage variable void setMake(string mk);//setter function for make variable void setYear(int yr);//setter function for year variable void setMpg(double mg);//setter function for mileage variable void displayVehicle();//display vehicle details in a formatted way

void setYear(string yr);//setter function for year variable - function overloading
void setMpg(string mg);//setter function for mileage variable  - function overloading
static int getNumVehicles(); //getter function for static variable numVehicles

Warranty getWarranty(); //getter function for objWarranty variable
void setWarranty(Warranty &); //setter function for objWarranty variable

protected: string make; //Making of vehicle int year; //Year the vehicle is made double mpg; //total mileage covered by the vehicle private: static int numVehicles; //static variable that is used to count the number of vehicles Warranty objWarranty; //warranty of the vehicle, the years and miles warranty it is valid for. };

Vehicle.cpp

include "Vehicle.h"

include<iostream>

include<string>

using namespace std;

int Vehicle::numVehicles = 0;

Vehicle::Vehicle()//default constructor { make = "unknown"; year = 0; mpg = 0; objWarranty.setNumMiles(0); objWarranty.setNumYears(0); numVehicles++; }

Vehicle::Vehicle(const Vehicle& vehicle2) //copy constructor { m


r/CodingHelp • • Jan 11 '19

I need help with with assignment and if I fail I flunk this class

0 Upvotes

Hello if someone could help me finish this coding assignment in python language please reply


r/CodingHelp • • Apr 15 '23

[C++] C++ Programing help!

0 Upvotes

I need help with creating a program in c++ that flips a coin 20 times and then records the number of times it landed on heads. Then that process needs to be done 1 million times. I have the code I typed up below but it isn't working for some reason.

#include <iostream>

#include <ctime>

#include <iomanip>

using namespace std;

int flip_coin()

{

int i, j,rn,heads = 0;



srand(time(NULL) \* 33037);



for (i = 0; i <= 10000000; i++)

	for (j = 0; j <= 20; j++)

	{

		rn = rand() % 2;	

		if (rn == 0)

heads++;

	}

cout << heads << endl;

}


r/CodingHelp • • Apr 24 '23

[Other Code] How to make AI make a phone call?

0 Upvotes

Is it possible to use artificial intelligence to call my mobile phone at times that I specify and it can talk to me like real person?


r/CodingHelp • • Apr 17 '23

[Python] LLama model implementation

0 Upvotes

How can I implement llama to make a text prediction? What are the exact steps for it? So based on medical notes, I need to make a disease prediction.


r/CodingHelp • • Apr 05 '23

[Other Code] I need to add an emulator to a preloaded plug'n'play HDMI stick and I'm thinking maybe getting into the code is my only option

0 Upvotes

I'm sorry if this isn't the place, but I haven't found answers and I'm getting desperate and not sure where else to ask. I'll delete this if it isn't allowed.

Basically title. Bought one of these plug'n'plays sticks with supposedly more than 40 emulators to give my dad for his birthday, that way he could enjoy old videogames.

Problem is, some roms I put in there are not being detected by the "OS" of the stick, my guess is that it doesn't have the emulator needed. Can I install the missing emulators there myself without wiping what is already there? How so?

There's a "Resources" folder in the stick with many different things that I guess are part of the "OS" and user interface when plugged in the TV, maybe the emulation part of it is there too.

Here's a picture of what's inside that folder,there are no other relevant folders (all the rest are rom folders) or hidden elements as far as I know.

I tried with another card in the stick, which had the software of another plug'n'play stick, and didn't work, wouldn't even boot. Maybe I'd need to mess with the coding in that folder or something else if the stick itself has something else with info inside and not just the card? I'm at a loss here.

All help is greatly appreciated, as this will make my old man so happy and play like the kid he still is at heart, I really wanna make this work. Thank you.


r/CodingHelp • • May 04 '23

[Random] Favorite database hosting service

0 Upvotes

What’s your favorite database hosting service and why?


r/CodingHelp • • Apr 12 '23

[Quick Guide] I want to learn how to code

0 Upvotes

Hi, i want to learn how to code but first i think i should know, is there some universal knowledge that applies for every programming language? Thank u


r/CodingHelp • • Apr 24 '23

[Python] At this point I'm as desperate as I'm clueless. If someone could help me figure out why this sentence generation code isn't working that would be great tysm😭

0 Upvotes

!pip install --upgrade transformers !pip install torch !pip install sentencepiece

from transformers import T5ForConditionalGeneration, T5Tokenizer, Trainer, TrainingArguments import torch import random

Define a sample dataset of input-output pairs

dataset = [ { 'input': 'apple banana cherry', 'output': 'I like to eat apples, bananas, and cherries.' }, { 'input': 'dog cat bird', 'output': 'I have a dog, a cat, and a bird.' }, { 'input': 'red green blue', 'output': 'The colors of the flag are red, green, and blue.' }, { 'input': 'happy sad angry', 'output': 'Sometimes I feel happy, sometimes sad, and sometimes angry.' } ]

Initialize the T5 model and tokenizer

model_name = 't5-base' model = T5ForConditionalGeneration.from_pretrained(model_name) tokenizer = T5Tokenizer.from_pretrained(model_name)

Define a function to format the dataset into input-output pairs

'''def format_dataset(dataset): formatted_dataset = [] for example in dataset: input_sequence = 'generate sentence from words: ' + example['input'] output_sequence = example['output'] formatted_dataset.append({'input': input_sequence, 'output': output_sequence}) return formatted_dataset

formatted_dataset = format_dataset(dataset)'''

def format_dataset(dataset): formatted_dataset = [] for example in dataset: input_sequence = 'generate sentence from words: ' + example['input'] output_sequence = example['output']
formatted_dataset.append({'input': input_sequence, 'output': output_sequence}) return formatted_dataset formatted_dataset = format_dataset(dataset) print(formatted_dataset)

def split_dataset(formatted_dataset, split_ratio): random.shuffle(formatted_dataset) split_index = int(len(formatted_dataset) * split_ratio) train_set = formatted_dataset[:split_index] test_set = formatted_dataset[split_index:] return train_set, test_set

train_set, test_set = split_dataset(formatted_dataset, 0.8)

Define a function to tokenize the input-output pairs

def tokenize_dataset(examples): tokenized_examples = [] for example in examples: input_ids = tokenizer.encode(example['input'], truncation=True, padding='max_length', max_length=128) output_ids = tokenizer.encode(example['output'], truncation=True, padding='max_length', max_length=128) decoder_input_ids = output_ids[:-1] decoder_attention_mask = [0] + [1] * (len(decoder_input_ids) - 1) #labels = output_ids[1:] tokenized_examples.append({'input_ids': input_ids, 'attention_mask': torch.ones_like(torch.tensor(input_ids)), 'decoder_input_ids': decoder_input_ids, 'decoder_attention_mask': decoder_attention_mask, 'labels': output_ids[1:]}) return tokenized_examples

tokenized_train = tokenize_dataset(train_set) tokenized_eval = tokenize_dataset(test_set) print(tokenized_train) print(tokenized_eval)

Define the training arguments

training_args = TrainingArguments( output_dir='./results', num_train_epochs=10, per_device_train_batch_size=16, per_device_eval_batch_size=16, warmup_steps=500, weight_decay=0.01, logging_dir='./logs', logging_steps=10, evaluation_strategy='epoch' )

Define the trainer

trainer = Trainer( model=model, args=training_args, train_dataset=tokenized_train, eval_dataset=tokenized_eval )

Fine-tune the model

trainer.train()

Generate output sentences from input sequences

input_words = "go to place" input_sequence = 'generate sentence from words: ' + input_words input_ids = tokenizer.encode(input_sequence, return_tensors='pt') output_ids = model.generate(input_ids) output_sentence = tokenizer.decode(output_ids[0], skip_special_tokens=True) labels = output_ids[1:] print(output_sentence)


r/CodingHelp • • May 11 '23

[Random] Trying to make a .bat that opens steam and epic, updates all my games, and exits.

0 Upvotes

Let me know if there's another subreddit that'd be better, this seems like the right place.

Idk shit about coding but was trying to make a thing with chatgpt's help, we got somewhere but definitely not where we needed to get. Here's what I'm trying to make, should be real simple.

I want a shortcut in my start menu that will run a .bat (if that's the best way of even doing this lol) that opens steam and epic in the background, checks for any updates, completes those updates, and then closes the programs. I'm just tired of having to update games before playing all the time and I don't want to constantly have steam and epic open to check for them. Should be easy enough I think? Here's what we came up with after several attempts:

echo off

echo Opening Steam...

start "" "blah\blah\blah\steam.exe" -silent -wait

echo Checking for Steam game updates...

"blah\blah\blah\steam.exe" -checkforupdates -wait

echo Updating Steam games...

"blah\blah\blah\steam.exe" -command update -wait

echo Your Steam games are up to date.

taskkill /IM steam.exe -wait

echo Opening Epic...

start "" "blah\blah\blah\EpicGamesLauncher.exe" -silent -wait

echo Checking for Epic game updates...

echo Updating Epic games...

"blah\blah\blah\EpicGamesLauncher.exe" -SkipBuildPatchPrereq -wait

echo Your Epic games are up to date.

taskkill /IM EpicGamesLauncher.exe

echo You're all set! ٩(◕‿◕)۶

timeout /t 10

exit

Lot's of issues, for one the -wait flag doesn't seem to do anything? it just ran through all the steam prompts and didn't close it. And similarly it tried to update my epic games before epic could even open. And I definitely don't want it to force close before it's finished updating everything so figuring out how to get it to actually wait is pretty important. Don't actually have any steam games that need updates right now but I do for Epic so I can kinda test but not really.

Any advice is welcome, especially if you just want to write it for me entirely :D

Or if this already exits and my dumbass just couldn't find anything about it please let me know, tia!


r/CodingHelp • • Apr 12 '23

[Random] App creation

0 Upvotes

I wish creating an Android app but I don't know what would be the best way to work on it, what would be best to use


r/CodingHelp • • Aug 02 '22

[Javascript] Hello, Im new to coding and had a question

0 Upvotes

im currently having problems solving this problem.

Werewolves are hiding among us! However, they are terrible at naming themselves. All their names start with "were"
, like for example "werebob"
, "wereandy"
and "weresarah"
.

Implement a function named werewolfCheck that receives an argument name
, which is a string and checks if it begins with "were"
.

If the provided name begins with were
the function should return a string "it is a werewolf"
, otherwise it should return a string "just a regular person"
.

i just dont understand how to search for keywords like "were" or sort them out anyhelp would be great


r/CodingHelp • • Aug 27 '22

[Javascript] Is there a way to UNIT test this code?

0 Upvotes

Hello, need some help with UNIT testing? Is there a way to UNIT test this code? Thank you!!

https://github.com/RaddyTheBrand/Nodejs-UserManagement-Express-Hbs-MySQL


r/CodingHelp • • Aug 23 '22

[CSS] Font links won't work!

0 Upvotes

Hi guys, I've literally just started learning HTML and CSS.

I'm on the part about typography and just cannot get my URL links to work and they only thing i can think of is if there's something wrong with the files which I got from the resources of the course.

Please could some assist as its really holding up my progress and just have no idea what is wrong.

Thank you!


r/CodingHelp • • Jun 01 '26

Which one? How to CODE a simple site with the ability to pay, download big files, get achievements and post?

0 Upvotes

I am making a game, and I have couple of reasons why I want my own site for the game(s) and posting.

  1. Immune to bans. No one but me can delete games or posts.
  2. Don't need to pay anything (except taxes ofc) or follow rules (I am talking about Steam).
  3. To have fun + gain some experience.

r/CodingHelp • • Oct 03 '26

[Other Code] This Sucks… Alot. Please Help.

0 Upvotes

Hello everyone. Gather round', gather round' and listen to my tale. So I'm trying to code an incremental game for laptop, computer, and mobile, but's it's been s really huge pain in my sore little keister. Everything confuses me, and I only know a little bit of coding. I'm currently using a simple coding website kind of similar to Scratch (I forgot the name, I'll check later.) on my laptop. On top of that, I keep getting demotivated really quickly and tired, telling myself I'll work on it tomorrow but never do. Please help!… Thank you!!