|
Hi
I am adding a string to listbox as a 8 bit ansi string for example the string is "8FED90" ending with a null
however when the MeasureItem method is called
itemData points to the string as wide so it display in memory as 38 00 46 00 45 00 44 00 39 00 30 00
I have Character set as "NOT SET" in my property pages -> Advanced in Visual Studio
Thanks
|
|
|
|
|
That does not make sense. The data pointed to by the MEASUREITEMSTRUCT is what you have set when you create the control. However, whether it is ANSI or Unicode does not matter, as the actual display dimensions will be the same.
|
|
|
|
|
Use an input file
An instructor has asked you to write a program that can tell him if his students have passed or
failed his course. He has a file that contains the following information:
• first name
• last name
• five quiz grades
• the midterm exam grade
• the final exam grade
Your program must read these values into variables then use those variables to calculate the
final average and finally display that average to the screen.
Requirements:
1. All input comes from a file – grades.txt. You may NOT ask for input from the professor. This
file is posted on Canvas for your program to use.
2. Remember: Your program must calculate the final average including those quizzes. All the
quizzes averaged together count as much as a test. So, to calculate the final, you need to
calculate the quiz average first, then average the midterm + final + quiz average.
3. Display the student’s last name first, comma, space and first name. Follow that with the final
average as a whole number, rounded up
The file contains one line of data in the following order:
firstName lastName q1 q2 q3 q4 q5 midterm final
Remember, data must be read in sequentially! This means that the first name variable must be
initialized before the last name or the quiz one and etc.
Code:
#include <iostream>
#include <fstream>
using namespace std;
/* run this prgram using the console pauser or add your own getch, system('pause") or input look */
int main(int argc, char** argv)
{
string firstName,lastName;
int q1, q2, q3, q4, q5, midterm, final;
int quizaverage;
int average;
ifstream inFile;
inFile.open("grades.txt");
inFile>>firstName>>lastName>>q1>>q2>>q3>>q4>>q5>>midterm>>final;
//Calculate the quiz average.
quizaverage=(q1+q2+q3+q4+q5)/5;
average=(quizaverage+midterm+final)/3*100;
cout<<"Dobbs, Bob"<<" Average: "<<average;
inFile.close();
return 0;
I need help with this. I am trying to use the numbers given from a text file in the program.
|
|
|
|
|
Stephanie Foley wrote: I need help with this Exactly what help do you need?
|
|
|
|
|
I need to use an input file to find that course average. The course average is a mathematical expression involved in quiz average, midterm grade, and final grade. I am trying to get the program to read what is in the file. There is the first name, last name, and 7 numbers. I need to use these values in the program to get an average for the class.
-- modified 6-Jun-22 16:22pm.
|
|
|
|
|
Well you stated that in your original question. But you have still not explained what your problem is.
|
|
|
|
|
How are your results different from what is expected? Also, showing the files exact contents would be helpful.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
I found, a statement,
int &a = 1;
the statement can be built in QT Creator, mingw_64.
while on Programiz: Learn to Code for Free[^]
Got,
gcc /tmp/BlXEG8NqhU.c -lm
/tmp/BlXEG8NqhU.c: In function 'main':
/tmp/BlXEG8NqhU.c:6:15: error: expected identifier or '(' before '&' token
6 | const int &a = 2;
so the int &a = 1;
is that right?
a is a bias name of "1" in rodata?
|
|
|
|
|
I suspect that whatever QT Creator is doing is somehow creating a const reference . e.g.
int &a = 1; const int &b = 2;
Consider what int &a = 1 means: I.E. create a reference to the integer 1. If that were to compile successfully then consider
int &a = 1;
a = 2;
std::cout << 1 + 1 << '\n'; By the rules of C++, at least as I understand them, that should print 4, since you've changed the value of 1 to 2 at the assignment statement.
Keep Calm and Carry On
|
|
|
|
|
You are trying to use a C++ construct in a C-language program.
|
|
|
|
|
is a floating point number still considered a number? I`m talking about a number that is not whole. Like for instance 0.01 feels like less than a 'number'
|
|
|
|
|
|
|
Victor, Richard thanks for your useful feedback.
views from an 'average' user.
|
|
|
|
|
You're welcome. That website is really useful for any mathematical issues.
|
|
|
|
|
|
There is the function `Sys_Milliseconds`:
<pre>int curtime;
int Sys_Milliseconds (void)
{
static int base;
static qboolean initialized = false;
if (!initialized)
{
base = timeGetTime() & 0xffff0000;
initialized = true;
}
curtime = timeGetTime() - base;
return curtime;
}
Used in time calculation in the Quake 2 main game loop implementation:
//...
oldtime = Sys_Milliseconds();
//...
while (1) {
//...
while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) {
if (!GetMessage(&msg, NULL, 0, 0))
Com_Quit();
sys_msg_time = msg.time;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
do {
newtime = Sys_Milliseconds();
time = newtime - oldtime;
} while (time < 1);
//...
}
I'm wondering about the usage of the `Sys_Milliseconds` at all. What's the point in `base = timeGetTime() & 0xffff0000` line? Why are they applying the 0xffff0000 mask on the retrieved time? Why not just use the `timeGetTime` function directly:
oldtime = timeGetTime();
while (1) {
while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) {
if (!GetMessage(&msg, NULL, 0, 0))
Com_Quit();
sys_msg_time = msg.time;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
do {
newtime = timeGetTime();
time = newtime - oldtime;
} while (time < 1);
}
|
|
|
|
|
Member 15212768 wrote: What's the point in `base = timeGetTime() & 0xffff0000` line?
To avoid being too close to rollover point. From "timeGetTime function | Microsoft Docs"[^]:
Quote: The return value wraps around to 0 every 2^32 milliseconds, which is about 49.71 days. This can cause problems in code that directly uses the timeGetTime return value in computations, particularly where the value is used to control code execution. You should always use the difference between two timeGetTime return values in computations.
Mircea
|
|
|
|
|
Thanks to parallel processing these days you can feed in your game loop a constant value as time variable. (there is no fluctuation between frames as far as time is concerned). You should care about Frame Rate Independent movement only if you`re developing a game meant to hit the store shelf.
modified 5-Jun-22 2:07am.
|
|
|
|
|
Hello!, this is my first post on this forum and i'm trying to understand how this works, so if this is not the proper way of asking for help or this is in the wrong subforum just let me know please!
I'm currently studying App Development, and as sort of a "final project" to pass the course, me and my group have to make a proyect that tracks both users and their data consumption.
Since we're restricted to using codeblocks and c language, I wanted to get some insight on how to improve the visual aspect of the cmd, and user experience overall.
I havent found many content of this kind online so any tutorial or explainatory about this subject would be very helpfull, since we havent been taught too much about this side of the coding, and I think this will be a great adition to the proyect, and learning experience overall.
Thanks!
|
|
|
|
|
|
Thanks for answering!
The project has to be fully working on our teacher's computer, so no plugins or external libraries are allowed, whatever resources we can use has to be already installed on CodeBlocks, GNU Compiler vanilla version. Also this is our first proyect so any tips on this matter would be wellcomed .
|
|
|
|
|
Sorry, but without some actual problem details there is nothing much we can offer.
|
|
|
|
|
This seems like a question that should be easy to find an answer to, but I'm not finding anything very convenient...
What I will want to do with this, is to be able to right-click on a folder in Explorer, and have an item "run my program on this folder" available...
I've found two example programs which do this, but each have drawbacks for my application;
1. one is a C# application (which I'm not familiar with, though it *is* pretty similar).
Also, this CodeProject application is using registry modification to do the job; I would prefer to find a link somehow to the Explorer menu, then use InsertMenuItem() from WinAPI to add a link to my application...
2. that brings me to the second example that I found; it's in an older Platform SDK, in a utility called Shell\SampView... that application *does* do what I wish; however, that application is over 8500 lines long!! I am hoping to find a more concise solution to the problem...
Can anyone provide any guidance or example code for this??
I use C++, and build with the MinGW (32-bit) toolchain...
and yes, I realize that once I get *this* issue resolved, I'll still have a variety of other issues to resolve, such as finding the path to my application, and dealing with selection of wrong items (ideally, perhaps just grey out my menu item if the target is not a folder), and many other things, but for now, I just want to find a concise, clear solution to this one problem.
|
|
|
|
|