Ehsan
lol
Ehsan
#best
Ehsan
🙂 🙂
RC
How to combine struct to a function in c??
Anonymous
In short for a struct to become a function you would need to have a static char array with the opcodes of the compiled function you want. You can then have a function pointer pointing to the beginning of that array. Make sure that the memory region the array resides in is actually executable.
But yeah, as said this is very unlikely what you need and so far i have only seen this being used in hacky and/or malicious projects.
RC
I mean this is possible, but very unlikely what you need. What exactly are you trying to do?
#include <stdio.h>
typedef struct {
int number,age;
char name[50],info[100];
} follow;
void create(){
FILE *p;
if((p= fopen("Myfile.txt","w")==NULL));{
puts("File could not be found!");
} else{
follow records{1, "", "",2};
for (int i = 1; i <= 100; i++) {
fwrite(&records, sizeof(follow), 1, p);
}
fclose(p);
}
}
int main(){
create();
}
RC
Andrew
Check brackets in your first “if” statement in ‘create’ function. I think you should close bracket after ‘p=fopen(…)’
RC
Maybe it's in
follow records={..}!
RC
Andrew
Only that?
I don’t know that’s only what I noticed at first reading:)
Sorry for bad English
RC
Nik0
good
Ausir
Hi guys, I need some info. What tf is wrong with SIGUSR1?
I'm using sigaction and kill sending SIGUSR1, the process that should receive the signal just ignore it, just SIGUSR1, I changed SIGUSR1 with SIGPIPE, just for debugging, and it's work fine. Can someone explain me wtf is going on? I'm losing hope. TY
Anonymous
klimi
He he "real scratch" meaning not std lib nor graphical api? Must be fun
H
Hello guys, This is my project. There are errors. Can someone help me solve it?
This is the title of the project
Car rental management system (add, search, edit, and remove cars), functions for renting cars for a specific period.
H
#include <iostream>
using namespace std;
struct Cars
string mark &#91:10] = {"Hyundai", "BMW". "Mercedes", "Audi". "Tesla","Skoda", "Volkswagun". "Toyota". "Ford");
string model &#91:10]= {"2016MD":"2018AS","2018DS","2017LA", "20180W","2005Ps","2008PW","2010QW", "2016SA"};
string color &#91:10]={"Red", "black","yellow", "Blue","Red","Brown","Silver", "Black","grey");
string maxs_peed &#91:10]={"100 Km/h","150 Km/h","150 Km/h","170 Km/h","130 Km/h","140 Km/h","130 Km/h","120 Km/h","150 Km/h");
int price &#91; 10 ]={100.200.300.500.200.250.400.600.900} ;
int date &#91:10] = {2010,2012,2013,2017,2018,2005,2008,2010,2014};
struct Lessee
string Name &#91:10];
string Natio_ID &#91;10):
int payment_acc &#91; 10) :
};
//Declaring struct
Cars car
Lessee lessee;
//First output
void Minu o
{
int num=1;
for(int i=0;i&lt:9;+11)
{
cout&lt;&lt;" titit":
cout&lt;&lt;"Enter" &lt;&lt;num&lt;&lt;"\t- To Select "&lt;&lt;car.mark&#91;i]&lt;&lt;endl;
num++;
}
}
//Second output
void Details (int the Choice)
{
system("CLS");
cout&lt;&lt:"n\n'n titt-
cout&lt;&lt;" titit You Have Selected - "&lt;&lt;car.mark&#91;the Choice-1]&lt;&lt;endl;
cout&lt;&lt;"\t\t\t--
---'n 'n":
cout&lt;&lt;" titit Model : "&lt;&lt;car model&#91the Choice-1]&lt;&lt;endl;
cout&lt;&lt;"\t\t\tColor : "&lt;&lt;car.color&#91 the Choice-1]&lt;&lt;endl;
cout&lt;&lt;" tittMaximum Speed: "&lt;&lt;car.maxs_peed&#91 theChoice-1]&lt;&lt;endl;
cout&lt;&lt;"\t\t\tPrice : "&lt;&lt;car.price&#91;the Choice-1]&lt;&lt:"K"&lt;&lt;endi:
}
//check lessee credit
void check (int i)
{
if(lessee.payment_acc&#91:]] >= car.price&#91:j])
cout&lt;&lt;"\n\n\n\t\t\tProcess has been done successfully!!" &lt;&lt;endl;
else
cout&lt;&lt;"\n\n\n\t\t\t Not Available " &lt;&lt;endl;
}
//User Inputcpo
void user_input (int theChoice)
{
system("CLS");
int i=the Choice-1 ;
cout&lt;&lt;" te
cout&lt;&lt;" te tPlease Provide Your Personal Details : \n";
cout&lt;&lt;" telt
cout&lt;&lt;"n NOTE: PROVIDE FIRST NAME ONLY, DONOT ENTER SPACE WHILE PROVIDING NAME, 'n PAYMENT WON'T PROCEED IF THE GIVEN AMOUNT IS LESS THEN
THE RATE OF CAR'n'n\n\n";
cout&lt;&lt;" the tEnter Your Name : ";
cin>>lessee. Name&#91.j]
cout&lt;&lt;" tit Enter Your National ID :":
cin>>lessee.Natio_ID&#91:]:
cout&lt;&lt;" te Payment Amount":
cin>>lessee.payment_acc&#91.j];
check(i):
}
int main
{
int login:
login:
string decide="yes" ;
cout&lt;&lt;" titt------
cout&lt;&lt;" tit SIMPLE CAR RENTAL SYSTEM n";
cout&lt;&lt;" titleWelcome to Our Company, Choose from the menu : "&lt;&lt;endl;
cout&lt;&lt;" titt
while( decide!="exit")
Minuo:
cout&lt;&lt;"\n\n\n titt Your Choice:";
int the Choice
cin>>theChoice;
Details(the Choice);
cout&lt;&lt;"n'n'ntit Are You Sure, you want to rent this Car? (yes/no/exit):",
cin>>decide :
if(decide=="yes") {
user_input(the Choice):
cout&lt;&lt;"\n\n\tit tDo you want to continue ?(yes/no)";
cin>>decide:
if (decide=="no") break;
system("CLS");
}
else {
if(decide=="no")
{
system("CLS");
continue ;
}
else if (decide=="exit")
{
system("CLS");
cout&lt;&lt;"\n\n\n\t\t\tBrought To You By code-projects.org":
break;
}
}
}
return 0;
}
##???
int login({
string pass="";
char ch;
cout &lt;&lt;"\n\n\n\n\n\n\n\t\tititit Simple Car Rental System Login";
cout &lt;&lt; "n'n'n'n'n'n'n titttttEnter Password":
ch= _getch();
while(ch != 13){//character 13 is enter
pass.push_back(ch):
cout &lt;&lt;'*;
ch = _getch();
}
if(pass == "pass") {
cout &lt;&lt; "n\n\n\n\t\tititit Access Granted! Welcome To Our System 'n'n";
system("PAUSE"):
system("CLS");
}else{
cout &lt;&lt; "n\n\n'n titititit Access Aborted. Please Try Again!!\n";
system("PAUSE");
system("CLS");
login:
}
}
klimi
#include <iostream>
using namespace std;
struct Cars
string mark &#91:10] = {"Hyundai", "BMW". "Mercedes", "Audi". "Tesla","Skoda", "Volkswagun". "Toyota". "Ford");
string model &#91:10]= {"2016MD":"2018AS","2018DS","2017LA", "20180W","2005Ps","2008PW","2010QW", "2016SA"};
string color &#91:10]={"Red", "black","yellow", "Blue","Red","Brown","Silver", "Black","grey");
string maxs_peed &#91:10]={"100 Km/h","150 Km/h","150 Km/h","170 Km/h","130 Km/h","140 Km/h","130 Km/h","120 Km/h","150 Km/h");
int price &#91; 10 ]={100.200.300.500.200.250.400.600.900} ;
int date &#91:10] = {2010,2012,2013,2017,2018,2005,2008,2010,2014};
struct Lessee
string Name &#91:10];
string Natio_ID &#91;10):
int payment_acc &#91; 10) :
};
//Declaring struct
Cars car
Lessee lessee;
//First output
void Minu o
{
int num=1;
for(int i=0;i&lt:9;+11)
{
cout&lt;&lt;" titit":
cout&lt;&lt;"Enter" &lt;&lt;num&lt;&lt;"\t- To Select "&lt;&lt;car.mark&#91;i]&lt;&lt;endl;
num++;
}
}
//Second output
void Details (int the Choice)
{
system("CLS");
cout&lt;&lt:"n\n'n titt-
cout&lt;&lt;" titit You Have Selected - "&lt;&lt;car.mark&#91;the Choice-1]&lt;&lt;endl;
cout&lt;&lt;"\t\t\t--
---'n 'n":
cout&lt;&lt;" titit Model : "&lt;&lt;car model&#91the Choice-1]&lt;&lt;endl;
cout&lt;&lt;"\t\t\tColor : "&lt;&lt;car.color&#91 the Choice-1]&lt;&lt;endl;
cout&lt;&lt;" tittMaximum Speed: "&lt;&lt;car.maxs_peed&#91 theChoice-1]&lt;&lt;endl;
cout&lt;&lt;"\t\t\tPrice : "&lt;&lt;car.price&#91;the Choice-1]&lt;&lt:"K"&lt;&lt;endi:
}
//check lessee credit
void check (int i)
{
if(lessee.payment_acc&#91:]] >= car.price&#91:j])
cout&lt;&lt;"\n\n\n\t\t\tProcess has been done successfully!!" &lt;&lt;endl;
else
cout&lt;&lt;"\n\n\n\t\t\t Not Available " &lt;&lt;endl;
}
//User Inputcpo
void user_input (int theChoice)
{
system("CLS");
int i=the Choice-1 ;
cout&lt;&lt;" te
cout&lt;&lt;" te tPlease Provide Your Personal Details : \n";
cout&lt;&lt;" telt
cout&lt;&lt;"n NOTE: PROVIDE FIRST NAME ONLY, DONOT ENTER SPACE WHILE PROVIDING NAME, 'n PAYMENT WON'T PROCEED IF THE GIVEN AMOUNT IS LESS THEN
THE RATE OF CAR'n'n\n\n";
cout&lt;&lt;" the tEnter Your Name : ";
cin>>lessee. Name&#91.j]
cout&lt;&lt;" tit Enter Your National ID :":
cin>>lessee.Natio_ID&#91:]:
cout&lt;&lt;" te Payment Amount":
cin>>lessee.payment_acc&#91.j];
check(i):
}
int main
{
int login:
login:
string decide="yes" ;
cout&lt;&lt;" titt------
cout&lt;&lt;" tit SIMPLE CAR RENTAL SYSTEM n";
cout&lt;&lt;" titleWelcome to Our Company, Choose from the menu : "&lt;&lt;endl;
cout&lt;&lt;" titt
while( decide!="exit")
Minuo:
cout&lt;&lt;"\n\n\n titt Your Choice:";
int the Choice
cin>>theChoice;
Details(the Choice);
cout&lt;&lt;"n'n'ntit Are You Sure, you want to rent this Car? (yes/no/exit):",
cin>>decide :
if(decide=="yes") {
user_input(the Choice):
cout&lt;&lt;"\n\n\tit tDo you want to continue ?(yes/no)";
cin>>decide:
if (decide=="no") break;
system("CLS");
}
else {
if(decide=="no")
{
system("CLS");
continue ;
}
else if (decide=="exit")
{
system("CLS");
cout&lt;&lt;"\n\n\n\t\t\tBrought To You By code-projects.org":
break;
}
}
}
return 0;
}
##???
int login({
string pass="";
char ch;
cout &lt;&lt;"\n\n\n\n\n\n\n\t\tititit Simple Car Rental System Login";
cout &lt;&lt; "n'n'n'n'n'n'n titttttEnter Password":
ch= _getch();
while(ch != 13){//character 13 is enter
pass.push_back(ch):
cout &lt;&lt;'*;
ch = _getch();
}
if(pass == "pass") {
cout &lt;&lt; "n\n\n\n\t\tititit Access Granted! Welcome To Our System 'n'n";
system("PAUSE"):
system("CLS");
}else{
cout &lt;&lt; "n\n\n'n titititit Access Aborted. Please Try Again!!\n";
system("PAUSE");
system("CLS");
login:
}
}
You have copied this from some website right?
H
I got this from my group
klimi
Right, so its not your code and you dont understand it... Nice
klimi
Firstly, remove the HTML entities with some online convertor...
H
Anonymous
Can someone tell me how I should proceed after completing DSA foundations with popular problems? I give CC challenges. I've decided to at least continue and do some problems on Hackerrank (maybe until I get a 5*).
What should I do in par with it, to enhance my problem solving skills?
Should I start solving on Codeforces then or GFG/ Leetcode?
PS : I'm in 2nd year
Anonymous
Earl B
Andrew
Anonymous
any one who is good at c++
Anonymous
Do real projects.
I did web dev projects last sem. Would do some more and something on Data Science.
Anonymous
Because I don't think I can pull off hard questions at first. So lemme get a good hang of it
Anonymous
Anonymous
just a suggestion
Anonymous
Yea I will.
Nish
try hacker rank
I am not a programmer but my job involves writing python scripts and interacting with different APIs, which I am good at.
But I suck at solving hackerrank type of questions. I've tried going through some data structures and algorithms courses. Any tips on what should I be learning if the end goal is to be able to solve those hackerrank / leetcode challenges?
Nish
Or if there are any specific books / course I can read or take.
Suka
Anonymous
V01D
Why does this code segfault when I use new?
https://pastebin.com/L9YsbwV4
V01D
I'm trying to allocate memory for a function upon construction
V01D
ohh
V01D
why is it recursive?
z
why is it recursive?
new a will call a() constructor. So you call a() constructor inside a() constructor.
V01D
oh I see.
So how would I go about allocating memory when a class is constructed
V01D
Like a logging class, I have a logging class that will be used alot and I wanna be able to just `Log().info("foo")`without worrying about manual memory allocation
z
z
I mean, allocate memory for what?
V01D
The class itself
V01D
or the object
V01D
yeah then it was an object
z
this is the pointer to it.
V01D
But I need to allocate memory for some function if I use it alot right
V01D
Why else would I see foo_class *foo_obj = new foo_class()
Anonymous
Does anyone know how to define a specialisation of a template using typename, where it executed on part when it is double/int and the other when we it gets first iterator of type string
Anonymous
Hello all
I AM Ankit Kumar and
I have five years of experience in website development
Jasur Fozilov 🐳
Is the hacking.cpp website good or bad for learning c ++?
Mahi_way❤
Does any one over here have any experience in site reliability engineering?😇
Mahi_way❤
i.e in Testing department, related!!
Sandeep
// C++ implementation of the approach
#include <bits/stdc++.h>
using namespace std;
// Function to return the maximum profit
// that can be made after buying and
// selling the given stocks
int maxProfit(int price[], int start, int end)
{
// If the stocks can't be bought
if (end <= start)
return 0;
// Initialise the profit
int profit = 0;
// The day at which the stock
// must be bought
for (int i = start; i < end; i++) {
// The day at which the
// stock must be sold
for (int j = i + 1; j <= end; j++) {
// If byuing the stock at ith day and
// selling it at jth day is profitable
if (price[j] > price[i]) {
// Update the current profit
int curr_profit = price[j] - price[i]
+ maxProfit(price, start, i - 1)
+ maxProfit(price, j + 1, end);
// Update the maximum profit so far
profit = max(profit, curr_profit);
}
}
}
return profit;
}
// Driver code
int main()
{
int price[] = { 100, 180, 260, 310,
40, 535, 695 };
int n = sizeof(price) / sizeof(price[0]);
cout << maxProfit(price, 0, n - 1);
return 0;
can anybody tell me the thought process to write a code like this on my own
Anonymous
hello anyone help me out to program a quadratic formula using c++
Hermann
anyone use ns3?. is possibile create custom mobility?
Anonymous
hi
Anonymous
// C++ implementation of the approach
#include <bits/stdc++.h>
using namespace std;
// Function to return the maximum profit
// that can be made after buying and
// selling the given stocks
int maxProfit(int price[], int start, int end)
{
// If the stocks can't be bought
if (end <= start)
return 0;
// Initialise the profit
int profit = 0;
// The day at which the stock
// must be bought
for (int i = start; i < end; i++) {
// The day at which the
// stock must be sold
for (int j = i + 1; j <= end; j++) {
// If byuing the stock at ith day and
// selling it at jth day is profitable
if (price[j] > price[i]) {
// Update the current profit
int curr_profit = price[j] - price[i]
+ maxProfit(price, start, i - 1)
+ maxProfit(price, j + 1, end);
// Update the maximum profit so far
profit = max(profit, curr_profit);
}
}
}
return profit;
}
// Driver code
int main()
{
int price[] = { 100, 180, 260, 310,
40, 535, 695 };
int n = sizeof(price) / sizeof(price[0]);
cout << maxProfit(price, 0, n - 1);
return 0;
can anybody tell me the thought process to write a code like this on my own
Its a simple recursion.
Aditi s
Can we place two or more catch blocks together to catch and handle multiple types of exceptions thrown by a try block.
Aditi s
Aditi s
And does c++ compiler check if any error is caught or not
Hanz
Aditi s
Jasur Fozilov 🐳
Anonymous
https://learnxinyminutes.com/docs/c++/