"Not an allowed type" in Turbo C++ - turbo-c++

I'm trying to make a grading system.So what i want to do is take 1/3 of the value of outputgrade and add it with 2/3 of the value of outputgrade2, I tried midterm1=(outputgrade()*1/3)+(outputgrade2*2/3) but I receive an error which is
Not an allowed type
Please somebody help me on what to do.
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
double AAO,Quizzes,Project,MajorExam,Midterm;
void inputprelim()
{
clrscr();
gotoxy(3,4);cout<<"Input Prelim Grade";
gotoxy(1,6);cout<<"Attendance/Ass./Oral: ";cin>>AAO;
gotoxy(1,7);cout<<"Project: ";cin>>Project;
gotoxy(1,8);cout<<"Quizzes: ";cin>>Quizzes;
gotoxy(1,9);cout<<"Major Exam: ";cin>>MajorExam;
gotoxy(1,11);cout<<"Prelim Grade: ";
}
int getgrade(double a, double b, double c, double d)
{
double result;
result=(a*0.10)+(b*0.20)+(c*0.30)+(d*0.40);
cout<<setprecision(1)<<result;
return result;
}
void outputgrade()
{
getgrade(AAO,Project,Quizzes,MajorExam);
getch();
}
void inputmidterm()
{
gotoxy(33,4);cout<<"Input Midterm Grade";
gotoxy(29,6);cout<<"Attendance/Ass./Oral: ";cin>>AAO;
gotoxy(29,7);cout<<"Project: ";cin>>Project;
gotoxy(29,8);cout<<"Quizzes: ";cin>>Quizzes;
gotoxy(29,9);cout<<"Major Exam: ";cin>>MajorExam;
gotoxy(29,11);cout<<"Temporary Midterm Grade: ";
gotoxy(29,12);cout<<"Final Midterm Grade: ";
}
void outputgrade2()
{
getgrade(AAO,Project,Quizzes,MajorExam);
getch();
}
void main()
{
inputprelim();
gotoxy(15,11);outputgrade();
inputmidterm();
gotoxy(54,11);outputgrade2();
gotoxy(55,11);
Midterm1=(outputgrade()*1/3)+(outputgrade2()*2/3);
}

Your functions outputgrade() and outputgrade2() are of return type void.
In order to use them in midterm1=(outputgrade()*1/3)+(outputgrade2*2/3) you need to change their return type as int/double/float,etc.
If I have understood the logic of your code correctly then edit the two functions as:
double outputgrade()
{
return getgrade(AAO,Project,Quizzes,MajorExam);
}
double outputgrade2()
{
return getgrade(AAO,Project,Quizzes,MajorExam);
}
What I have done is changed the return type to double and at the same time the two functions are now returning whatever value getgrade returns.

outputgrade() and outputgrade2() need to return a numeric value for use in the calculation.
Right now they don't return anything.

Related

i am getting runtime error vecause of commented if statement how to solve?

vector<vector<int>> floodFill(vector<vector<int>>& ig, int sr, int sc, int nc) {
int n= ig.size();
int m=ig[0].size();
// cout<<m<<endl;
queue<pair<int,int>> q;
if(ig[sr][sc]==nc)
return ig;
int t = ig[sr][sc];
q.push({sr,sc});
while(!q.empty()){
pair<int,int>v=q.front();
q.pop();
ig[v.first][v.second]=nc;
if(v.first>0){
if(ig[v.first-1][v.second]==t)
{
q.push({v.first-1,v.second});
}
}
if(v.first<n){
if(ig[v.first+1][v.second]==t)
{
q.push({v.first+1,v.second});
}
}
/*if(v.second>0){
if(ig.at(v.first).at(v.second-1) ==t)
{
q.push({v.first,v.second-1});
}
}
*/
if(v.second<m){
if(ig[v.first][v.second+1]==t)
{
q.push({v.first,v.second+1});
}
}
}
return ig;
}
how to solve this? error is in the third if statement which i have commented out.when i commented the third if statement it was compiled properly and when it was included it shows runtime error .
Can anyone help me with this?
I think the problem is v.second-1 because it's out of bound if v.second equals 0. You need to handle the bound of indices before accessing invalid (negative) indices.

Save a single character

everyone.
I've created a simple textedit application.
I would like to take the single character whenever the user writes it using the keyboard.
I've thought to solve the problem in the following way:
void MainWindow::on_textEdit_textChanged()
{
QString str= ui->textEdit->toPlainText();
if (str.size()==0){
pos=0;
} else {
if(pos<str.size()) {
QChar char_prel=str.at(pos);
pos++;
chars.push_back(char_prel);
} else {
pos=0;
QString str=ui->textEdit->toPlainText();
chars.clear();
for(int i = 0; i < str.length(); i++) {
QChar char_prel=str.at(i);
chars.push_back(char_prel);
pos++;
}
}
}
}
The solution doesn't work because everytime, i read the entire string on the edit block using:
QString str= ui->textEdit->toPlainText();
and from that string i take the last inserted character.
I want to do the same thing without using the toPlaintText().
Thanks for answering
If you handle the KeyPressEvent of the QTextEdit, you'll have a parameter of QKeyEvent* type, let's call this one "e".
Then you can use "e->text()" to get the corresponding character.

Pass a typed function as a parameter in Dart

I know the Function class can be passed as a parameter to another function, like this:
void doSomething(Function f) {
f(123);
}
But is there a way to constrain the arguments and the return type of the function parameter?
For instance, in this case f is being invoked directly on an integer, but what if it was a function accepting a different type?
I tried passing it as a Function<Integer>, but Function is not a parametric type.
Is there any other way to specify the signature of the function being passed as a parameter?
Dart v1.23 added a new syntax for writing function types which also works in-line.
void doSomething(Function(int) f) {
f(123);
}
It has the advantage over the function-parameter syntax that you can also use it for variables or anywhere else you want to write a type.
void doSomething(Function(int) f) {
Function(int) g = f;
g(123);
}
var x = <int Function(int)>[];
int Function(int) returnsAFunction() => (int x) => x + 1;
int Function(int) Function() functionValue = returnsAFunction;
To strongly type a function in dart do the following:
Write down the Function keyword
Function
Prefix it with its return type (for example void)
void Function
Append it with parentheses
void Function()
Put comma separated arguments inside the parentheses
void Function(int, int)
Optionally - give names to your arguments
void Function(int foo, int bar)
Real life example:
void doSomething(void Function(int arg) f) {
f(123);
}
Edit: Note that this answer contains outdated information. See Irn's answer for more up-to-date information.
Just to expand on Randal's answer, your code might look something like:
typedef void IntegerArgument(int x);
void doSomething(IntegerArgument f) {
f(123);
}
Function<int> seems like it would be a nice idea but the problem is that we might want to specify return type as well as the type of an arbitrary number of arguments.
For reference.
int execute(int func(int a, int b)) => func(4, 3);
print(execute((a, b) => a + b));
You can have a function typed parameter or use a typedef
void main() {
doSomething(xToString);
doSomething2(xToString);
}
String xToString(int s) => 's';
typedef String XToStringFn(int s);
void doSomething(String f(int s)) {
print('value: ${f(123)}');
}
void doSomething2(XToStringFn f) {
print('value: ${f(123)}');
}
DartPad example
This is what typedefs are for!

QList to QQmlListProperty

I'm trying to pass QList into QML using QQmlListProperty, as official documentation says:
QQmlListProperty::QQmlListProperty(QObject *object, void *data, CountFunction count, AtFunction at)
My code is:
QQmlListProperty<TTimingDriver> TTiming::getDrivers()
{
return QQmlListProperty<TTimingDriver>(this, &m_drivers, &TTiming::count, &TTiming::driverAt);
}
int TTiming::count(QQmlListProperty<TTimingDriver> *property)
{
TTiming * timing = qobject_cast<TTiming *>(property->object);
return timing->m_drivers.count();
}
TTimingDriver * TTiming::driverAt(QQmlListProperty<TTimingDriver> *property, int i)
{
TTiming * timing = qobject_cast<TTiming *>(property->object);
return timing->m_drivers.at(i);
}
But I'm getting an error:
no matching function for call to 'QQmlListProperty<TTimingDriver>::QQmlListProperty(TTiming*, QList<TTimingDriver*>*, int (TTiming::*)(QQmlListProperty<TTimingDriver>*), TTimingDriver* (TTiming::*)(QQmlListProperty<TTimingDriver>*, int))'
return QQmlListProperty<TTimingDriver>(this, &m_drivers, &TTiming::count, &TTiming::driverAt);
I think <ou are mixing two of the QQmlListProperty constructor overloads.
The one that takes the QList<T*> does not need pointers to functions.
So this should be sufficient
QQmlListProperty<TTimingDriver> TTiming::getDrivers()
{
return QQmlListProperty<TTimingDriver>(this, &m_drivers);
}
Assuming that m_drivers is of type QList<TTimingDriver*>

Issue with Recursive Methods ("missing return statement")

so I have a program that is running a bunch of different recursive methods, and I cannot get it to compile/run. The error is in this method, according to my computer:
public static int fibo(int n)
// returns the nth Fibonacci number
{
if (n==0)
{
return 0;
}
else if (n==1)
{
return 1;
}
else if (n>1)
{
return fibo(n-1) + fibo(n-2);
}
}
I have this method called correctly in my main method, so the issue is in this bit of code.
I think I can help you in this. Add return n; after your else if. Outside of the code but before the last curlicue.
The code will work as long as n ≥ 0 btw; another poster here is right in that you may want to add something to catch that error.
Make sure all possible paths have a return statement. In your code, if n < 0, there is no return statement, the compiler recognizes this, and throws the error.
public static int fibo(int n)
// returns the nth Fibonacci number
{
if (n<=0)
{
return 0;
}
else if (n==1)
{
return 1;
}
else // All other cases, i.e. n >= 1
{
return fibo(n-1) + fibo(n-2);
}
}

Resources